Get and insert the last modified date, time and user name in Excel

Send Us a Sign! (Contact Us!)

[print-me]

The following code is a good VBA macro, to include in ThisWorkbook default module in a XLSM file (Excel macro-enabled file), to add and update, to each save, the user and the date and time at which the document has been modified.

This code uses default workbook events (embedded in every Excel workbook) to execute some tasks before and after a save process (when the user hit the Save button, to be clear).

NOTE: the code needs to be added using the VBE development environment integrated in Excel, by using Alt+F11 combination keys.

Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Application.Volatile True
LastSaveDate = FileDateTime(ThisWorkbook.FullName)
Sheets("Sheet1").Range("A2").Value = LastSaveDate
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Sheets("Sheet1").Range("A1").Value = Environ("username") End Sub
Private Sub Workbook_Open() Application.Volatile True LastSaveDate = FileDateTime(ThisWorkbook.FullName) Sheets("Sheet1").Range("A2").Value = LastSaveDate End Sub

1 thought on “Get and insert the last modified date, time and user name in Excel”

  1. The following method will let you, on saving an Excel document, to update values, in specific cells on a specific “status” sheet (pre-existing in document) the last user that have modified the document and the date and time at which the document has been saved. Read more on Heelpbook:

    Get and insert the last modified date, time and user name in Excel – http://heelpbook.altervista.org/2016/get-and-insert-the-last-modified-date-time-and-user-name-in-excel/ #heelpbook #howto #excel #microsoft #excel

Comments are closed.