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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.