Prompt to save doc as "NAME.doc" after opening in code?

K

kiln

From MS Access 2000 I'm opening word 2000 docs via code, and inspecting
the BuiltInDocumentProperties("Keywords") property. In theory I change
nothing in the doc. However when I try to close the active document, a
dialog pops up suggesting I save the doc I'd opened via code as
"NAME.doc". Can't figure out why? Something triggered by looking into
BuiltInDocumentProperties? Calling .Save doesn't seem to help, and that
seems wrong anyways...

Code snippet:

dim objWord as Object
' etc other vars

Set objWord = CreateObject("Word.Application")
strDir = "C:\"
strDirFileRequest = strDir & "*.doc"
strFileName = Dir(strDirFileRequest)
Do While strFileName <> ""
strPathFileName = strDir & strFileName
objWord.Documents.Add strPathFileName
strDocKeywords = objWord.ActiveDocument.BuiltInDocumentProperties
("Keywords")
if strDocKeywords = "Something" then
'whatever, nothing to do with Word
end if
objWord.ActiveDocument.Close
strFileName = Dir
Loop
set objWord = Nothing
 
J

Jay Freedman

Hi, kiln,

It's stupid, but just looking at any of the BuiltInDocumentProperties
does dirty the document -- probably because the counts of characters,
words, paragraphs etc. are updated in case you ask about them.

To kill the prompt, add a parameter to the Close command:

objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

If the VBA compiler complains that the constant wdDoNotSaveChanges
isn't defined, use its numeric value of 0.
 
K

kiln

Thanks, that really helps!

Hi, kiln,

It's stupid, but just looking at any of the BuiltInDocumentProperties
does dirty the document -- probably because the counts of characters,
words, paragraphs etc. are updated in case you ask about them.

To kill the prompt, add a parameter to the Close command:

objWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

If the VBA compiler complains that the constant wdDoNotSaveChanges
isn't defined, use its numeric value of 0.
 

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