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!

Does MS Word have an equivalent to MS Excel's Change event? 1

Status
Not open for further replies.

JohnRobin

Programmer
Oct 1, 2005
1
CA
If a user opens a Word document and then closes it, I want to put some code in the File_Close event that will check whether the file has been changed since the last time it was saved. Excel has a Worksheet_Change event that does even more than I need. Is there any workaround in Word that would duplicate that?

Details:
I have some code that when a user opens up a Word document with a date appended to the name, as in "Proposal 2005 09 30", the code will change the name to the current date, as in "Proposal 2005 10 01". Any files with earlier dates serve as a backups to the file just opened under the new name. To change the name of a document requires saving the file under the new name.
If the user then does nothing but look at the document and close it without making any changes, there is no point in having the duplicate file saved on the hard disk. I therefore want to delete it.
How can I quickly tell whether the user made any changes in the document when he or she closes it, so that I can, if necessary, delete useless files?
Thanks for any help you can provide!
 
Hi JohnRobin,

Every Document has a Saved property which indicates whether it has been changed since last saved. Off the top of my head I don't know if changing the file name switches the flag but you can set it yourself, so ..

On Open ..
Code:
[i]Document_Ref[/i].Name = "[i]NewName[/i]" [green]' or whatever you do[/green]
[i]Document_Ref[/i].Saved = True
And on close
Code:
If [i]Document_Ref[/i].Saved = True Then
    [green]' Don't Save[/green]
Else
    [green]' Do Save[/green]
End If


Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top