by Allen Wyatt
(last updated October 20, 2018)
Kimberly wonders if there is a formula she can use to put into a cell the date the workbook was last saved. Even if she opens the workbook every day, she only wants the date updated every time she chooses to save.
There is no formula to do this; Excel doesn't have the native capability. You can, however, create a simple macro that will stick a date value into a cell whenever you save the workbook. This is based on the BeforeSave event, which belongs to the ThisWorkbook object:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _ Cancel As Boolean) Sheets(1).Range("A1").Value = Now() End Sub
This macro places the date (actually, the value returned by the Now function) into cell A1 of the first worksheet in the workbook. That cell should be formatted within Excel to whatever format you desire. There is a potential drawback to this macro—if you use Save As (to save the workbook under a different name) and then choose to cancel the save, the date is still updated because it took place before the save—meaning, it took place just as Excel was starting to save the workbook, not after the workbook was actually saved.
It should be noted that Excel also includes an AfterSave event which you may be tempted to use to update information. It, unfortunately, has a few loopholes, as well, and offers nothing more foolproof than the BeforeSave event does.
If you prefer, you can use a slightly different macro-based approach. This one relies on a regular macro, not an event handler:
Function LastModified() As Date Application.Volatile LastModified = ThisWorkbook.BuiltinDocumentProperties("Last Save Time") End Function
Within whatever cell you want the date to appear, you would call the macro in this way:
The formula returns the date and time the workbook was last saved, and you can format it in any way desired. Since the function is noted as volatile, it is updated continuously, whenever the worksheet is recalculated.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13575) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
VBA makes it easy to copy a worksheet from the current workbook into a brand-new workbook. You may want to delete some ...Discover More
ISBNs are used to uniquely identify books. You may need to know if an ISBN is valid or not, which involves calculating ...Discover More
The security features built into Excel allow you to digitally sign your macros so that users can rest assured that they ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.