Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

AutoClose Macro to Remind User to Update Modification Date

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barb R. - 28 Mar 2005 21:41 GMT
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
Jezebel - 28 Mar 2005 22:17 GMT
Yes, you can create an AutoClose macro.

>I have several documents that need to have a modification date updated
>within
[quoted text clipped - 9 lines]
> Thanks in advance,
> Barb Reinhardt
Barb R. - 29 Mar 2005 01:19 GMT
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?

> Yes, you can create an AutoClose macro.
>
[quoted text clipped - 11 lines]
> > Thanks in advance,
> > Barb Reinhardt
Jezebel - 29 Mar 2005 03:15 GMT
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.

> Well, I can create a macro, but don't know what to put into it to get it
> to
[quoted text clipped - 17 lines]
>> > Thanks in advance,
>> > Barb Reinhardt
Greg - 29 Mar 2005 03:38 GMT
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
Barb R. - 29 Mar 2005 15:25 GMT
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

> Barb,
>
[quoted text clipped - 16 lines]
>  End If
> End Sub
Greg - 29 Mar 2005 16:46 GMT
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
Barb R. - 29 Mar 2005 17:21 GMT
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?

> Barb,
>
[quoted text clipped - 62 lines]
> http://www.gmayor.com/installing_macro.htm
> http://gregmaxey.mvps.org/word_tips.htm
Greg - 29 Mar 2005 19:19 GMT
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
Barb R. - 29 Mar 2005 16:43 GMT
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.  

> Barb,
>
[quoted text clipped - 16 lines]
>  End If
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.