getting word to prompt to save on Close

H

Hal Tz

Look like I have the opposite problem of a lot of threads here. I'm a total
newbie to Word Automation, am doing Document.Close, and have tried
oWordDoc.Close SaveChanges:=wdPromptToSaveChanges,
OriginalFormat:=wdPromptUser
and many variation on it, it always closes the doc saving any changes
without ptompting. Here's the code snippet. Any ideas? Thanks.

Dim oWD As Word.Application
Dim oWordDoc As Word.Document
Set oWD = New Word.Application
Set oWordDoc = oWD.Documents.Open("c:\z.doc")
oWD.Visible = True
oWD.Activate
MsgBox ("hit OK to close")
oWordDoc.Close SaveChanges:=wdPromptToSaveChanges ,
OriginalFormat:=wdPromptUser
 
S

Shauna Kelly

Hi Hal

I think the problem here is that the Word document isn't "dirty": there are
no changes to be saved, so the user isn't prompted to save any.

For testing, use oWordDoc.Saved = False before the oWordDoc.Close line. This
"dirties" the document. Word then thinks there are changes to be made, and
the prompt to save works as intended.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
H

Hal Tz

Sorry about the long delay..I was out 6 weeks. Anyway, I just tried your
suggestion, to no avail. Any other ideas? Thanks.
 

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