Prompt document properties using VBA

Using MS Word 2003, is it possible to get a message box indicating the last modified date and the name of the user?

This macro could be executed every time one file is opened? Or it must be executed manually?

Thank you for your comments,

Who is Participating?
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
Hello alcani,

copy the code below into the ThisDocument module.

In your document, click Tools - Macro - Visual Basic Editor
Double click ThisDocument under Microsoft Word Objects and paste the code below into the code window. Close the Visual Basic Editor and save the file.

Now, every time the document is opened a message box will pop up.

cheers, teylyn
Private Sub Document_Open()
Dim docActive As Document
Set docActive = ActiveDocument

If docActive.Path <> "" Then MsgBox _
    "Last saved on: " & docActive.BuiltInDocumentProperties(wdPropertyTimeLastSaved) & Chr(10) & _
    "Last saved by: " & docActive.BuiltInDocumentProperties(wdPropertyLastAuthor)

End Sub

Open in new window

Put a macro similar to the following in the Open event of the file you're interested in.
Private Sub Document_Open()
    Dim sLastAuthor As String
    Dim dtLastModified As Date
    sLastAuthor = ActiveDocument.BuiltInDocumentProperties(wdPropertyLastAuthor)
    dtLastModified = ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeLastSaved)
    MsgBox sLastAuthor & " saved this document " & dtLastModified & "."
End Sub

Open in new window

Take a look at this for Auto Open:

Here are the properties you want to reference
Private Sub Document_Open()

    Dim d As Word.Document
    Set d = ActiveDocument
    MsgBox d.BuiltInDocumentProperties(wdPropertyLastAuthor) & vbCrLf & _
End Sub

Open in new window

alcaniAuthor Commented:

This is working great.

I have some issue concerning the date & time displayed.

As you know, each computer has his own date & time.

Is it possible to set an "absolute" time depending in one machine of the network?
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:

the time displayed is the time that is stored within the document as the last time it was saved. If it was saved with computer A, which runs 10 minutes late compared to a central server, and then is opened by computer B, which runs the same time as a central server, there is no way of figuring out if the computer that it was saved on had the correct time at the time of last save or not.

What are you trying to do?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.