How to set word document as saved

W

Word.user

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
 
D

Doug Robbins - Word MVP

Use ActiveDocument.Close wdDoNotSaveChanges if you really do not want to
save the changes that you have made.

--
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
 
R

Russ

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
 
M

Michael Bednarek

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.

Works here:
Sub FakeSaved()
Selection.TypeText Text:="Hello World!"
ActiveDocument.Saved = True
End Sub
and subsequent Ctrl+F4 will not prompt.
 
W

Word.user

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
 
R

Russ

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.
 
W

Word.user

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
 
G

Graham Mayor

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.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Russ

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.
 

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