VBA for Last Saved At Timestamp with Hours Minutes and Seconds Ago

Useful to have as a button or invoke overtime to alert when you have forgotten to save

me@jaykilleen.com wrote this over 7 years ago and it was last updated over 7 years ago.


← Back to the Posts

I use the below function and submodule in Excel VBA and have a button on my ribbon I click. This will just display when my workbook was last saved (date with time) and the hours, minutes and seconds ago.

I have some code that gets run on Workbook.Save events and so when I close I get an alert saying the workbook has not been saved. Rather than switch off the alert I have this button I click to verify that I have in fact saved it recently.

Function LastSavedTimeStamp()
  LastSavedTimeStamp = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function

Sub ShowLastSavedTimeStamp()
  Dim hours As Integer: hours = DateDiff("h", LastSavedTimeStamp, Now())
  Dim minutes As Integer: minutes = DateDiff("n", LastSavedTimeStamp, Now())
  Dim seconds As Integer: seconds = DateDiff("s", LastSavedTimeStamp, Now())
  MsgBox "This workbook was Last Saved at " & vbNewLine & LastSavedTimeStamp & " or " & hours & ":" & (minutes Mod 60) & ":" & (seconds Mod 60) & " ago"
End Sub