I am opening word document and then inserting sections and assigning some
values to bookmark and then at the end I have
ActiveDocument.Saved = True
But still when I close the file without doing anything, the message comes
'Do you want to Save changes?'
What do I need to set in the AutoOpen macro so that unless there is any
change made after opening document, Word would not ask the Do you want to
save message.
Thanks in Advance
Doug Robbins - Word MVP - 14 Aug 2007 07:49 GMT
Use ActiveDocument.Close wdDoNotSaveChanges if you really do not want to
save the changes that you have made.

Signature
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
>I am opening word document and then inserting sections and assigning some
> values to bookmark and then at the end I have
[quoted text clipped - 8 lines]
>
> Thanks in Advance
Russ - 14 Aug 2007 09:27 GMT
Word,
You're welcome in advance.
You didn't actually save it, with that line of code, so Word was polite
enough to ask if you did want the changes saved. I think
ActiveDocument.Saved was meant to be queried and not set. To save a document
use ActiveDocument.Save
This is from Word VBA Help, which is a good source of information:
Save Method Example
This example saves the active document if it's changed since it was last
saved.
If ActiveDocument.Saved = False Then ActiveDocument.Save
This example saves each document in the Documents collection without first
prompting the user.
Documents.Save NoPrompt:=True, OriginalFormat:=wdOriginalDocumentFormat
If Sales.doc is open, this example saves a version of Sales.doc, with a
comment.
For Each doc in Documents
If Instr(1, doc.Name, "Sales.doc", 1) > 0 Then
doc.Versions.Save Comment:="Minor changes to intro"
End If
Next doc
> I am opening word document and then inserting sections and assigning some
> values to bookmark and then at the end I have
[quoted text clipped - 8 lines]
>
> Thanks in Advance

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Michael Bednarek - 14 Aug 2007 14:15 GMT
>I am opening word document and then inserting sections and assigning some
>values to bookmark and then at the end I have
[quoted text clipped - 6 lines]
>change made after opening document, Word would not ask the Do you want to
>save message.
Works here:
Sub FakeSaved()
Selection.TypeText Text:="Hello World!"
ActiveDocument.Saved = True
End Sub
and subsequent Ctrl+F4 will not prompt.

Signature
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"
Word.user - 15 Aug 2007 00:54 GMT
Thanks everyone for their suggestions.
When I open a document I populate bookmarks and sections, and then when user
tries to close window of word, I want to stop that "do you want to save"
message, cause for user he has not done any changes.
If I use ActiveDocument.Close wdDoNotSaveChanges, then it will always close
without saving, how would I know that user has typed something after
populating bokkmarks etc? If I know user has typed something then I can set
ActiveDocument.Close wdDoSaveChanges else DoNOTSave
Russ - 15 Aug 2007 06:13 GMT
Word,
Reread my message, I talked about querying .Saved
Whenever you make changes to a document, .Saved automatically becomes false.
One of the simple one line examples I reprinted was
If ActiveDocument.Saved = False Then ActiveDocument.Save
adapt it for your use.
> Thanks everyone for their suggestions.
> When I open a document I populate bookmarks and sections, and then when user
[quoted text clipped - 4 lines]
> populating bokkmarks etc? If I know user has typed something then I can set
> ActiveDocument.Close wdDoSaveChanges else DoNOTSave

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Word.user - 15 Aug 2007 06:30 GMT
I think I have not made myself clear here. The point is I do not want to save
the document unless user himself selects to save the document.
So I cannot use: If ActiveDocument.Saved = False Then ActiveDocument.Save
> Word,
> Reread my message, I talked about querying .Saved
[quoted text clipped - 11 lines]
> > populating bokkmarks etc? If I know user has typed something then I can set
> > ActiveDocument.Close wdDoSaveChanges else DoNOTSave
Graham Mayor - 15 Aug 2007 07:04 GMT
If the last active line of your autoopen macro is
ActiveDocument.Saved = True
then provided you don't do anything else that would affect that flag, such
as adding text, printing etc, then you should be able to close without a
prompt.

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> I think I have not made myself clear here. The point is I do not want
> to save the document unless user himself selects to save the document.
[quoted text clipped - 23 lines]
>>
>> drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ - 15 Aug 2007 07:39 GMT
Word,
You said in your first message that you had it at the end. Was it the last
line? Other than the End Sub line, of course.
> If the last active line of your autoopen macro is
> ActiveDocument.Saved = True
> then provided you don't do anything else that would affect that flag, such
> as adding text, printing etc, then you should be able to close without a
> prompt.

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID