AutoClose Macro to Remind User to Update Modification Date

B

Barb R.

I have several documents that need to have a modification date updated within
the document when substantial changes are made. I've considered using field
codes, but the only problem is that the documents sometimes need to be
editted to fix formatting errors and they aren't truly a change to the
substance of the document. Is there some way to create an autoclose macro
that will prompt the user to enter the modification date (if necessary). I
know this isn't foolproof, but it might be better than nothin'.

Thanks in advance,
Barb Reinhardt
 
B

Barb R.

Well, I can create a macro, but don't know what to put into it to get it to
flag for date change. How would I do that?
 
J

Jezebel

Probably simplest is to set up a custom document property for
'LastSignificantChange' or some such. In your macro prompt the user to
update the value if they wish. You can also test the document's .Saved
property -- if TRUE, nothing at all has changed and you can skip the prompt.
 
G

Greg

Barb,

You could use a documentment property to store a manually entered last
modification date and use a pop up mesage box as a reminder. As a
quick test I just used the Built in propert "Manager" to provide the
data. You would probably want to create a custom property:

Private Sub Document_Close()
Dim lastMod
lastMod = ActiveDocument.BuiltInDocumentProperties("Manager").Value

If ActiveDocument.Saved = False Then
If MsgBox("The document modification date is " & lastMod & ". Do you
want to change" _
& " the document modificatin date?", vbYesNo) = vbYes Then
WordBasic.FileProperties
ActiveDocument.Save
End If
End If
End Sub
 
B

Barb R.

This is getting where I need to be. I do have several questions:

1) How do I create a document property?
2) I have quite a few documents that will need this. I assume I need to
put the property in all documents.
3) I also assume that I need to put the macro in all documents.
4) How do I get the macro to run when I close the document?
5) I got a syntax error in the If MsgBox line. The subsequent lines were
listed in red. (can you tell that I've not done much Visual Basic before?)

Thank you for your assistance to date.

Barb Reinhardt
 
B

Barb R.

I've gotten it working to a point. When I try to change to Custom
properties, I get a problem at this statement:

lastMod = ActiveDocument.CustomDocumentProperties("ModificationDate").Value

I have created a Custom property with the name "ModificationDate", but for
some reason, it doesn't like it.
 
G

Greg

Barb,

Most document properties are already created just empty.

Open a File
Click File>Properties>Summary
Do you see data in Title, or Author, or Company? These are built in
DocProperties with data provided by the filename and your User
settings.

To display this data in the document, type Author, select it, press
CTRL+F9, select it and press ALT+F9.

For the sample I gave you yesterday I just used the Manager field to
store a manually entered date and time.

You will probably want to create a your own Custom docProperty to hold
this data. Use the custom tab and create away. In the sample below, I
used "Recorded Date" a predefined custom document propert.

To display custom properties you need { DocProperty "Recorded Date" }
or both the field name and property name in the field codes.

I assume that each document will have its own significant change
variable so yes you will need the variable in each document.

You don't necessarily have to put the macro in every document. You can
put it in a template if you want to, however it will fire on closing
any document that you create with that template. You wouldn't want it
in your normal.dot.

If you have the macro named and set up correctly it will fire on the
close event. Some links to following lower in this string (or thread,
whatever they are called).

The error was due to line breaking in this message window. I have
tried to shorten the lines to prevent, but I can't guarantee it will
come across clean. Lets hope so.

Yes I can tell, but I have a lot to learn myself.

Private Sub Document_Close()

Dim lastMod
Dim oFld As Field

lastMod = ActiveDocument.CustomDocumentProperties("Recorded
Date").Value
If MsgBox("The document modification date is " & lastMod & "." _
& " Do you want to change the document modification" _
& " date?", vbYesNo) = vbYes Then
WordBasic.FileProperties
For Each oFld In ActiveDocument.Fields
If InStr(oFld.Code.Text, "Recorded Date") Then
oFld.Update
Exit For
End If
Next
'ActiveDocument.Save
End If

End Sub

http://word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm
http://www.gmayor.com/installing_macro.htm
http://gregmaxey.mvps.org/word_tips.htm
 
B

Barb R.

Greg,

Instead of taking the user to the Properties menu, I'd like to save the
current date as the Custom date property. How do I do this?
 
G

Greg

Something like this should do:

Private Sub Document_Close()
Dim lastMod
Dim myDate
Dim myTime
Dim NewModDate
Dim oFld As Field

myDate = Format(Date, "MMMM dd, yyyy")
myTime = Format(Time, "HH:mm")
NewModDate = myDate & " " & myTime

lastMod = ActiveDocument.CustomDocumentProperties("Modification
Date").Value
If MsgBox("The document modification date is " & lastMod & "." _
& " Do you want to change the document modification" _
& " date?", vbYesNo) = vbYes Then
ActiveDocument.CustomDocumentProperties("Modification Date").Value =
NewModDate
For Each oFld In ActiveDocument.Fields
If InStr(oFld.Code.Text, "Modification Date") Then
oFld.Update
Exit For
End If
Next
End If

End Sub
 

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