?
Solved

Disable popup window when closing Ms Word document

Posted on 2012-09-16
13
Medium Priority
?
1,491 Views
Last Modified: 2012-09-20
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

Open in new window

and
Sub AutoClose()
    Documents("FindUnsignedDocuments.doc").Close wdDoNotSaveChanges
End Sub

Open in new window

0
Comment
Question by:thenelson
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 8

Expert Comment

by:Scott Thompson
ID: 38403592
If you want to disable Microsoft Word from asking you about any document, you should be able to disable this function following the instructions listed here.

http://www.ehow.com/how_7553534_stop-save-changes-closing-document.html
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 38403609
Try application.displayalerts = false
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38403893
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

Open in new window

0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 39

Author Comment

by:thenelson
ID: 38404309
None of those suggestions worked.

BTW, Chris,
    application.displayalerts = false
is the correct syntax for Excel but for Word it is:
    Word.Application.DisplayAlerts = 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/
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38404436
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?
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38404476
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.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 38404505
Wdalertsnone and false are both zero so there is no problem from that perspective

Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 38404519
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
0
 
LVL 39

Author Comment

by:thenelson
ID: 38408135
AutoClose does fire before the form closes but
    Application.DisplayAlerts = wdAlertsNone
    ActiveDocument.Saved = True
do not stop the popup dialog from displaying.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38408395
Try the troubleshooting steps in the Microsoft article:
http://support.microsoft.com/default.aspx/kb/921541
0
 
LVL 39

Author Comment

by:thenelson
ID: 38416153
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
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 38417089
Your document seems to be used ans an interactive Windows form, rather than a document.
It has ActiveX controls, (four command buttons and a listbox). The opening code adds items into the listbox, and there seems to be a bug in which setting the Saved property to true does not suppress the warning in this case.

If nothing is added to the listbox, but edits are done to the text, the code is effective.

You have a couple of options. You could actually save the document:
Sub AutoClose()
    Application.DisplayAlerts = wdAlertsNone
    ActiveDocument.SaveAs Environ("temp") & "\temp.doc"
End Sub

Open in new window

or (and I think better), you could have a UserForm instead of a document.
0
 
LVL 39

Author Closing Comment

by:thenelson
ID: 38417347
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
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question