can't get Document.Close wdPromptToSaveChanges to work

H

Hal Tz

Hi. I want to open a doc in an exisitng Word instance and if there's none to
open it in a new one. Work fine, but when I open in a new one, then
Document.Close (wdPromptToSaveChanges )
doesn't work - it doesn't prompt and does save the changes. The problem is
not there if I open in an existing instance. Any ideas? Thanks.

Private Sub Form_Load()
Dim oWD As Word.Application
Dim oWordDoc As Word.Document
On Error Resume Next
Set oWD = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set oWD = CreateObject("Word.Application")
End If
Set oWordDoc = oWD.Documents.Open("c:\z.doc", , , False)
oWD.Visible = True
oWD.Activate
MsgBox "hit OK"
oWordDoc.Close wdPromptToSaveChanges
Exit Sub
End Sub
 
D

Doug Robbins

Try inserting oWordDoc.Saved = False.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
H

Hal Tz

thanks, but that didn't do it. Now I can't even get it to work with an
existing Word instance, with or w/o the oWordDoc.Saved = False.
 

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