0
votes

I'm using MS Interop to open a generated file for a user, allow them to edit it and then close it, after which I save it for them (it's part of a larger process). Since the user doesn't need to save the file manually I would like to cancel that pop up dialog to save the file when the user tries to close the document. The following doesn't seem to work for me in a handler for the DocumentBeforeClose event:

App.ActiveDocument.Saved = true;

This seems like it should mark the Word document as saved, but doesn't.

Anyone come across this issue?

-nomad311

1
Does the event fire? The document being closed is an argument of the event handler (Sub app_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean), so I would simply try Doc.Saved = TrueDirk Vollmar
Yes it does, I can break in the method to debug. App.ActiveDocument references to that same Doc variable, but I tried doing it directly also and still no change :( I've also attempted to call close on the Doc with Save() set to false and Quit() on the Application object also setting save to false ...And nothing stops the pop up!!!!!!LostNomad311
Are there any other Word add-ins installed that might interfere?Dirk Vollmar
Nope, I've only used Word for this project since I installed it.LostNomad311
Are you sure you are not modifying the document after you set the Saved property to true? Try the following: Create a new Word document and type some text, press Alt+F11 to open the VBA editor then press Ctrl+G to display the Immediate Window. Now type ActiveDocument.Saved = True followed by return. Then close the document. The document should close without prompting you to save.Dirk Vollmar

1 Answers

0
votes

I found out I was creating a chain of events by calling the SaveAs() method of the document from the DocumentBeforeClose event handler. But, I was canceling the save (intended to only stop a user save) in the DocumentBeforeSave event handler. Thus, canceling the chain ...which stops the close operation, but the 'save changes' pop-up still gets launched?!

...Thought I would spell this out in case someone else gets as cleaver as I did :)

-nomad311