thenelson
asked on
Disable popup window when closing Ms Word document
I have created a Ms Word document that displays information collected by VBA. When I close the document by clicking on the X, I get the popup dialog message: "Do you want to save the changes of...." I don't want to save the document. How do I disable the message? I tried the following to no avail:
Sub AutoClose()
ActiveDocument.AttachedTemplate.Saved = True
ActiveDocument.Saved = True
End Sub
and
Sub AutoClose()
Documents("FindUnsignedDocuments.doc").Close wdDoNotSaveChanges
End Sub
Try application.displayalerts = false
Put a macro like this in the ThisDocument module of the document, its template or the Normal template:
Private Sub Document_Close()
If ActiveDocument.Name = "MyDoc.docx" Then
ActiveDocument.Saved = True
End If
End Sub
ASKER
None of those suggestions worked.
BTW, Chris,
application.displayalerts = false
is the correct syntax for Excel but for Word it is:
Word.Application.DisplayAl erts = wdAlertsNone
wdAlertsNone = 0
and
wdAlertsAll = -1
So false and true would work backwards in Word.
Go figure.
See: http://www.developerfusion.com/code/1130/turn-off-warning-messages-in-ms-office-applications/
BTW, Chris,
application.displayalerts = false
is the correct syntax for Excel but for Word it is:
Word.Application.DisplayAl
wdAlertsNone = 0
and
wdAlertsAll = -1
So false and true would work backwards in Word.
Go figure.
See: http://www.developerfusion.com/code/1130/turn-off-warning-messages-in-ms-office-applications/
Though I only tested it with the code put in the Normal template, my snippet did work. Have you tried using a breakpoint to see if it fires when a document is about to be closed?
AutoClose should also work. In fact it fires before the Document _Close event.
If neither work, then you might have some sort of Word internal setting problem, which would need debugging.
Do other Auto macros and the other Document_ events work?
It might be worth trying a new user profile.
If neither work, then you might have some sort of Word internal setting problem, which would need debugging.
Do other Auto macros and the other Document_ events work?
It might be worth trying a new user profile.
Wdalertsnone and false are both zero so there is no problem from that perspective
Chris
Chris
As Graham says it should work with auto close in this document certainly my test with auto close in this document containing this document saved = true works fine ... Display alerts did not which did surprise me.
Chris
Chris
ASKER
AutoClose does fire before the form closes but
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.Saved = True
do not stop the popup dialog from displaying.
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.Saved = True
do not stop the popup dialog from displaying.
Try the troubleshooting steps in the Microsoft article:
http://support.microsoft.com/default.aspx/kb/921541
http://support.microsoft.com/default.aspx/kb/921541
ASKER
The behavior is the same on three different computers including one computer that had office installed just today so it is unlikely to be a problem with Ms Word.
I have attached the file in question. It's purpose is to find and list files in subfolders with the name format of:
20120910 Consultation Report John Doe.doc
So You need to put a file with that name in a subfolder to the folder where you put the uploaded file: FindUnsignedDocuments.doc. If FindUnsignedDocuments.doc does not find a file, it will close without creating the message "Do you want to save the changes of...."
FindUnsignedDocuments.doc
I have attached the file in question. It's purpose is to find and list files in subfolders with the name format of:
20120910 Consultation Report John Doe.doc
So You need to put a file with that name in a subfolder to the folder where you put the uploaded file: FindUnsignedDocuments.doc.
FindUnsignedDocuments.doc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Graham,
The ActiveDocument.SaveAs Environ("temp") & "\temp.doc" suggestion is a quick and dirty solution. I don't think I want to spend the time rewriting the document as a UserForm right now.
Thanks
The ActiveDocument.SaveAs Environ("temp") & "\temp.doc" suggestion is a quick and dirty solution. I don't think I want to spend the time rewriting the document as a UserForm right now.
Thanks
http://www.ehow.com/how_7553534_stop-save-changes-closing-document.html