VB macro that puts "Last modified" date - TechRepublic
General discussion
March 16, 2006 at 03:20 PM
noyoki

VB macro that puts “Last modified” date

by noyoki . Updated 20 years, 3 months ago

I’m trying to write a macro in VB (it’s for Excel) that will give me the last date that the document was saved. I was intending it to run at startup (through Workbook_Open).

The problem I’m running into is that it appears to be saving the document after being run (I think). I’ll change the date (on my PC), run the macro, and end up with one date. Close and save. Change the date and run the macro again, but wind up with whatever date that day is.

Sub MyHeader3()
Dim sLMD As String

On Error Resume Next

sLMD = ActiveWorkbook.BuiltinDocumentProperties(“Last Save Time”)
If Err = 440 Then
Err = 0
sLMD = “Not Set”
End If
ActiveSheet.PageSetup.RightHeader = “Saved date ” _
& FileDateTime(ActiveWorkbook.FullName)
End Sub

Do I even need to do this in VB? Is there a better way? He just wants to have the “Last modified” date updated automatically, rather than having to remember to edit it. What am I doing wrong?

This discussion is locked

All Comments