Putting the Last Saved Date in a Cell

Written by Allen Wyatt (last updated June 26, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


9

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:

=LastModified()

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.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Replacing and Converting in a Macro

When you use a macro to process data you always run the risk of making that data unusable by Excel. This is especially ...

Discover More

Adding Vertical Lines at the Sides of a Word

Vertical lines are even easier to add around a word than are horizontal lines. There are a variety of methods you can use ...

Discover More

Adding Smart Quotes through Macro Text

When text is added to your document by a macro, and that text includes quotes or apostrophes, Word won't change the ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Macro, while Running, Stops Excel from Responding

When running a macro, have you ever seen Excel appear to stop responding? This can be frustrating, but there are a couple ...

Discover More

Getting Rid of Alphabetic Characters

When you need to get rid of characters in the middle of a cell value, the best way to do it is through the use of macros. ...

Discover More

Displaying the First Worksheet in a Macro

When creating macros, you often have to know how to display individual worksheets. VBA provides several ways you can ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 8?

2023-07-09 10:14:41

Willy Vanhaelen

Here is another approach. Insert the macro as descried in my comment of 6th June. Then insert the following UDF (User Defined Function) in a module:

Function SavedTime()
Application.Volatile
SavedTime = ThisWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function

Then enter =SavedTime() in cell A2.

When you open the workbook, A1 as well as A2 will display the same date+time namely the "Date modified" that is displayed in File Explorer. After a wile though when you progress with your work the time displayed in B2 will change. That will happen when Excel creates/updates an AutoRecovered file. That will also happen when you save your workbook without closing it.

That way you can monitor when the last AutoRecovered has been executed and if since then you did some important work save yourself the workbook by precaution.


2023-07-06 15:47:37

J. Woolley

@John
Re. my previous comment below, My Excel Toolbox includes the following function to return the last save date/time for a file:
=FileLastDate([FilePath])
FilePath is optional; default is the active workbook. If FilePath is not absolute (like "C:\Users\MyName\Documents\MyFile.xlsx") or that file does not exist, then FilePath is assumed to be relative to the active workbook's folder (like "MyFile.xlsx" or ".\SubFolder\MyFile.xlsx"
or "..\SiblingFolder\MyFile.xlsx").
See https://sites.google.com/view/MyExcelToolbox


2023-07-06 15:20:29

J. Woolley

Here are three ways to get the active workbook's last modified (saved) date using functions available in My Excel Toolbox:
=FileLastDate()
=INDEX(ListDocProperties(,,TRUE),12,2)
=VBAResult("ActiveWorkbook.BuiltinDocumentProperties(12)")
Notice "Last Save Time" is the 12th item in BuiltinDocumentProperties.
See https://sites.google.com/view/MyExcelToolbox
For more on this subject, see:
https://excelribbon.tips.net/T007764_Displaying_the_Last_Modified_Date.html
https://excelribbon.tips.net/T011099_Last_Saved_Date_in_a_Footer.html
https://excelribbon.tips.net/T011604_Date_Last_Edited.html


2023-07-06 08:30:24

Willy Vanhaelen

To avoid the SaveAs drawback of the first macro, you can use Excel's BuiltinDocumentProperties("Last Save Time") property by putting this macro in the ThisWorkbook code sheet:

Private Sub Workbook_Open()
Sheet(1).Range("A1") = ThisWorkbook.BuiltinDocumentProperties("Last Save Time")
End Sub


2023-07-06 00:32:57

Norm Thibodeau

Excel not providing a built-in LastSaved() date and time stamp function seems like a significant omission to me. This is a very commonly needed function for anyone why wants to tag the content in their file with this important info. As pointed out, Excel maintains save date as well as lots of other info in its file metadata. If we can write a function macro to pop this into a cell on a worksheet, then why can't Microsoft provide it as a built-in function so we could use it without having to make our workbooks macro enabled? The demand for this seems obvious to me just based on the returns when you do a Google search on it.
Two things are noteworthy.
1. I have seen many people who incorrectly use the =Today() function for the purpose of time stamping. But that simply displays the current system date each time the workbook is opened. That's useless as a time stamp. And misleading for any reader pf the file content.
2. MS Word DOES enable you to enter the Save date as text anywhere in your document (insert/quickparts/save date). Its ironic that a data centric app like Excel doesn't provide a quick way to insert this important element of data when Word, a mere word processor, does.


2020-05-13 13:15:43

John

Is there a way to return the last modified date of a different file by referencing a file path in the VBA code?


2020-01-14 11:49:02

sam

Is this only for when the entire workbook was last modified? Is there a code for each individual worksheet tab?


2018-10-22 16:36:24

Alex B

I personally would prefer to see Date Last Modified in the spreadsheet rather than date last saved and by adding an if statement to the "Sub" in the tip, the date will only update if excel thinks you have made changes (which is not foolproof.)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
        Cancel As Boolean)

    If Not ActiveWorkbook.Saved Then
        'This workbook contains previously unsaved changes
        Sheets(1).Range("A1").Value = Now()
   End If
End Sub


2018-10-22 16:07:27

Roy

There is another tip on Mr. Wyatt's site at this URL: https://excel.tips.net/T002285_Displaying_the_Last_Modified_Date.html .

It begins:

"If you look at the properties stored with a workbook, you will notice that Excel maintains quite a bit of information concerning the file. One of the items is a date and time that is simply noted as "Modified." Many people refer to this as the "last modified" date, but it really reflects the last time the workbook was saved."

and continues in telling you how to get the date which "really reflects the last time the workbook was save" and put it in a page header.

Seems one could do that, except put it in the desired cell rather than a page header.


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.