View Full Version : Solved: How do you replace Word's Save command?
New Daddy
10-22-2012, 06:06 AM
We have AutoClose, AutoOpen and AutoNew to automatically run macros upon closing, opening or creating a document. How come there is no AutoSave? In any event, how do you replace Word's native Save command? What I'd like to achieve is embed a custom document property that will tell me whether I have worked on that document in the past or not.
I have a feeling that this must be an easy one, but Google doesn't find useful information. (For example, Microsoft's own solution doesn't work. msdn.microsoft.com/en-us/library/office/ff837542.aspx
fumei
10-22-2012, 03:32 PM
You simply overwrite it.Sub FileSave()
' your code here
End SubI am not sure a document property is best; perhaps a document variable instead?
New Daddy
10-22-2012, 04:37 PM
You simply overwrite it.Sub FileSave()
' your code here
End SubI am not sure a document property is best; perhaps a document variable instead?
Oh... That wasn't too difficult..
Could you explain why document variable is better suited for my purpose than document property? I chose document property because you can peruse all the document properties (both built-in and custom) in the document properties dialog box.
fumei
10-22-2012, 06:06 PM
You said nothing about perusing. So yes, if you want to peruse through the GUI, a custom property would be fine.
However, if you want to use the data with programmatic flexibility, my choice would be a variable. For one thing unless someone else knows how to code, the data is much more private. Although of course if someone does know how to code it is not private at all.
Sub FileSave()
ActiveDocument.Variables("WorkedOn").Value = Format(Now, "dd:mm:yyyy")
ActiveDocument.Save
End Sub
Now, because the .Value is NOT "" you can tell it has been saved before, AND you have a date.
Yes, you can work with properties, and sure it could very well be what you want. Hard to say, as I do not know what you actally want the data for.
fumei
10-22-2012, 06:23 PM
An example?
Private Sub Document_Open()
Dim OKDate
OKDate = #10/1/2012# ' October 1, 2012
If ActiveDocument.Variables("WorkedOn").Value > OKDate Then
MsgBox "Document last save was " & _
ActiveDocument.Variables("WorkedOn").Value
Else
' ??? if the last save was before that date ???
End If
End SubIf the document was saved AFTER Oct 1, you get a message with the date actually saved. And of course a choice to do something else if it was saved before that date.
What exactly is your purpose?
New Daddy
10-23-2012, 10:14 AM
An example?
Private Sub Document_Open()
Dim OKDate
OKDate = #10/1/2012# ' October 1, 2012
If ActiveDocument.Variables("WorkedOn").Value > OKDate Then
MsgBox "Document last save was " & _
ActiveDocument.Variables("WorkedOn").Value
Else
' ??? if the last save was before that date ???
End If
End SubIf the document was saved AFTER Oct 1, you get a message with the date actually saved. And of course a choice to do something else if it was saved before that date.
What exactly is your purpose?
I guess your method could serve my purpose too.
What I'm trying to achieve is, when I save the document for the very first time, whether to save edit certain items - such as the company, author, etc. - in the document properties. Once I've decided to, or not to, edit these document properties, I don't want the document properties dialog box to pop up every time I save the document. Thus, a custom document property (or variable) to be switched on after the very first save.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.