Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Date Last Edited.

Date Last Edited

Written by Allen Wyatt (last updated July 16, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


4

As part of setting up a worksheet, you may want the header or footer to contain the date that the workbook was last edited. Excel doesn't maintain this information, but it does allow you to perform macros whenever certain events occur, such as changes to a workbook. All you need to do is add a macro such as the following to the ThisWorkbook object in the VBA Editor:

Private Sub Workbook_SheetChange(ByVal _
  Sh As Object, ByVal Target As Excel.Range)
    ActiveSheet.PageSetup.CenterFooter = _
      "Worksheet Last Changed: " & _
      Format(Now, "mmmm d, yyyy hh:mm")
End Sub

The macro results in each footer on each worksheet in the workbook having separate dates and times on them, since each worksheet would be updated at different times. You can change the destination property (.CenterFooter) to one of the other header or footer properties (.LeftHeader, .CenterHeader, .RightHeader, .LeftFooter, .RightFooter) as desired.

You may want the header or footer to instead include the date that the workbook was last saved. (This is what many people really view as the Òlast edit date.Ó) The information is visible in the Properties dialog box for a worksheet, but Excel has no menu selection or other command that allows you to insert this date into a header or footer. Instead, you must use a macro to add the desired information.

The best way to accomplish the task is to add a macro to the ThisWorkbook object that is triggered just before a workbook is saved:

Private Sub Workbook_BeforeSave(ByVal _
  SaveAsUI As Boolean, Cancel As Boolean)
    Dim sht
    For Each sht In Sheets
        sht.PageSetup.CenterFooter = _
          "Workbook Last Saved: " & _
          Format(Now, "mmmm d, yyyy hh:mm")
    Next
End Sub

This macro steps through each worksheet in the workbook and changes every center footer to have the date that the workbook was saved.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11604) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Date Last Edited.

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

Cross-Referencing to Line Numbers

Wouldn't it be nice to be able to do cross-referencing to line numbers within a document? Word doesn't have a built in ...

Discover More

Hyperlinking to a Specific Excel Worksheet

Creating a hyperlink to an Excel workbook is easy. With the information in this tip you can discover how to hone that ...

Discover More

Inconsistent Repeating of a Table Header Row

When you have a table that extends over multiple pages, you may want to have Word repeat a row or two at the top of each ...

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)

Creating Long Page Footers

Ever wish that you could create nice, long footers that appear at the bottom of each page when you print your worksheet? ...

Discover More

Putting a Different Date in a Header

Today's date is easy to add to a header, but what if you want to add a date that is adjusted in some manner? Adding ...

Discover More

Roman Numerals for Page Numbers

Yes, Excel can work with Roman numerals, and it even provides a worksheet function that converts to them. How you use ...

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 1 + 1?

2022-09-05 15:22:48

J. Woolley

For more on this subject, see my recent comment here: https://excelribbon.tips.net/T011099_Last_Saved_Date_in_a_Footer.html


2022-07-18 10:14:45

J. Woolley

Re. the VBA code in my previous comment:
This line of code
    If Right(sFoot, Len(Divi)) <> Divi Then
should be replaced by this line
    If Len(sFoot) > 0 And Right(sFoot, Len(Divi)) <> Divi Then
However, the code works OK even without this change.


2022-07-17 19:32:04

J. Woolley

Here is the last saved (a.k.a. modified) date and time for the active workbook:
    ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
The result is a VBA Date type numeric value. The following event code is an alternative to the Tip's Workbook_BeforeSave that might be slightly more efficient. It adds to the end of any unrelated CenterFooter.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Dim oSh As Object, dSave As Date, sFoot As String
    Dim n As Integer
    Const Prop As String = "Last Save Time"
    Const Stmt As String = "Workbook Last Saved: "
    Const Divi As String = vbCr
    Const Form As String = "mmmm d, yyyy, hh:mm am/pm"
    dSave = ActiveWorkbook.BuiltinDocumentProperties(Prop)
    For Each oSh In Sheets
        With oSh
            sFoot = .PageSetup.CenterFooter
            n = InStr(1, sFoot, Stmt)
            If n > 0 Then sFoot = Left(sFoot, (n - 1))
            If Right(sFoot, Len(Divi)) <> Divi Then
                sFoot = sFoot & Divi
            End If
            sFoot = sFoot & Stmt & Format(dSave, Form)
            .PageSetup.CenterFooter = sFoot
        End With
    Next oSh
End Sub


2022-07-16 05:34:51

Kiwerry

Thanks, Allen.
Your second macro will add a centre footer to each sheet; it may be worth some user's while to check the centre footer first, e.g by

If Sht.PageSetup.CenterFooter <> "" Then ...

and only update the date if the centre footer exists and has a previous date.


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.