Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop Save Changes Prompt - Word

Status
Not open for further replies.

esib

IS-IT--Management
Sep 10, 2004
35
US
I need to be able to control when a document can and cannot be saved. I am having trouble with the save changes prompts that comes up when the document or application is closed. I have tried everything i can think of to override...

' ActiveDocument.ActiveWindow.Close SaveChanges:=False
' ActiveDocument.Saved = True
' Application.DisplayAlerts = False
' Application.QuitobjWord.Quit SaveChanges:=False

I have tried these in AutoClose, AutoExit and Document_Close Subs.

Does anyone have an idea for me. I still consider myself new to VBA, so there is probably some trick I am not aware of.

Thanks
 
Private Sub Document_Close()
ActiveDocument.Saved = True
End Sub
 
Private Sub Document_Close()
If my_variable = my_condition Then
ActiveDocument.Saved = True
Else
End If
End Sub
 
Tahnks for the replry.

I have already tried all of the following in Document_Close:

' ActiveDocument.ActiveWindow.Close SaveChanges:=False
' ActiveDocument.Saved = True
' Application.DisplayAlerts = False
' Application.QuitobjWord.Quit SaveChanges:=False

But if there is a change to the document and the user choses:

file-close
file-exit
x box

The save changes always comes up...

Any thoughts?
 
You request is a little disjointed.

I need to be able to control when a document can and cannot be saved.

To my mind, that is a request to, well, control IF a document can be saved, or not. When??? Are you asking to prevent a user from saving a document? "Cannot be saved" implicitly tells me you may want to stop a save.

However, I am guessing, but I think what you want to know is(and tell me if I am wrong):

ActiveDocument.Close (wdDoNotSaveChanges)

There are three Save Options (and closely linked to the Close method).

wdDoNotSaveChanges
wdSaveChanges
wdPromptToSaveChanges

Another option is:

Documents.Save NoPrompt:=True

This saves ALL documents (and only ALL documents in the Documents collection), without any prompts. You can not use NoPrompt:=True on a single document...unless of course there IS only a single document in the Documents collection.

Are you trying to close Word itself afterwards? Are you trying to save the document by code, but prevent the user from doing so? Are you trying to save the document, and no bother the user to do so? Are you trying to save the document in the background, when the user is not seeing it?

In the last case Documents.Save NoPromopt:=True may be what you want.

Gerry
 
Gerry

Thank you for the reply. I should have been more specific in my original post. I am controlling where the document is being saved in the network and the name. Save-as is not allowed (I added code to FileSaveAs to prevent). Normal save will dynamically generate the file name based on certain field values (only after multiple checks have been satisfied).

But if the user changes the file, but then closes the file by one of the following three methods:

File-Close
File-Exit
X box close

It will by pass the FileSave and FileSaveAs code I have. I have tried to put code in the Document_close sub and it is being evaluated, but it still is not stopping the save changes event (or I guess that may be an auto_close event).

The main goal is that the user does not have any ability to dictate where this is saved and the name of the file...but because of what I described above, they can overwrite the original.

In the save current changes event, I would like to be able to perform the same edits/code as in the FileSave and FileSaveAs, or just stop the Save current changes event completely...

Hope that makes it more clear. I took a break in the middle of typing this message, so I hope it isn't all over the place.

Thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top