closing document - prompting to save changes

R

red6000

Hi, I want to run some code that closes all open documents and (if the doc
hasn't been saved) it prompts the user to save the changes. I have the
following:

Dim aDoc as Document
For Each aDoc In Documents
aDoc.Close SaveChanges:=wdPromptToSaveChanges
Next

However the code always saves the changes and I dont get prompted.

Any ideas?

Thanks.
 
J

Jonathan West

red6000 said:
Hi, I want to run some code that closes all open documents and (if the doc
hasn't been saved) it prompts the user to save the changes. I have the
following:

Dim aDoc as Document
For Each aDoc In Documents
aDoc.Close SaveChanges:=wdPromptToSaveChanges
Next

However the code always saves the changes and I dont get prompted.

Any ideas?

That code works for me. Therefore, there must be something different in your
setup. For instance, do you have an AutoClose macro created anywhere?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jonathan West

Jonathan West said:
That code works for me. Therefore, there must be something different in
your setup. For instance, do you have an AutoClose macro created anywhere?

By the way, I forgot to mention - the prompt only appears if there are
changes to be saved - i.e. if the Saved property of the document is False.
The document will be closed without prompting if the Saved property is True.
If you want to force a prompt irrespective of whether there are changes to
be saved, then place this line in the loop above the Close statement

aDoc.Saved = False


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
R

Russ

red6000,
That should prompt the user **if there are any changes to be saved in
file**. If there are no changes to the file and it has already been saved at
least once, it will close immediately.
If you want to force a prompt for every file use:

Dim aDoc as Document
For Each aDoc In Documents
aDoc.Saved = False
aDoc.Close SaveChanges:=wdPromptToSaveChanges
Next

Also a Document_Close() event handler could intercept and alter normal
closing of files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top