Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 2007 - Disable Save dialog box on 'X' 2

Status
Not open for further replies.

RP1America

Technical User
Aug 17, 2009
221
US
I would like to not allow users the option of saving a Word doc. I have already disabled the Save and Save As controls, yet when you click the 'X' to exit the document, a dialog box appears..."Do you want to save the changes to (DocName)?" With a Yes, No, and Cancel options.

I would like to either disable this and NOT save the document or somehow choose "No" via VBA.

I am assuming this needs to be done in the Document_BeforeClose event. I have scoured the web, tried numerous suggestions, yet have had no luck.

Any thoughts?

Thanks!
Ryan
 

This is from Excel, but I think it should work in Word as well:

[tt]DisplayAlerts = False[/tt]

Have fun.

---- Andy
 
Thanks for the reply, Andy!

However, I am not having any luck with DisplayAlerts. Any other suggestions?
 
Trying to completely disallow Save and SaveAs is doomed to failure. Disabling the controls does just that: disables the controls, not the functions behind them.

The easiest way to solve your immediate problem is perhaps with the DocumentBeforeClose event - just code "Doc.Saved = True" in it, and the user will not be prompted. This will suppress the prompt for all changes for all documents, which may be more dramatic then you want, however, and you may want to make the code conditional.



Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Thank you, Tony.

I seem to have accomplished this by using the Document_Close event.

Code:
Private Sub Document_Close()
    
    ActiveDocument.Saved = True
    
End Sub
 
For a specific document you can disable saving using application events with filter:
Code:
Private WithEvents wdApp As Word.Application

Private Sub Document_Close()
ThisDocument.Saved = True
End Sub

Private Sub Document_Open()
Set wdApp = Application
End Sub

Private Sub wdApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
If Doc Is ThisDocument Then
    Cancel = True
    SaveAsUI = True
End If
End Sub
Saving other documents is still enabled.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top