Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. 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: Last Saved Date in a Footer.

Last Saved Date in a Footer

by Allen Wyatt
(last updated June 6, 2015)

3

Lori wants the right side of the footer for her worksheet to include the date the workbook was last saved. Every time she tries to create a formula to do this, Excel displays an error message that states the "string is too long" and that she needs to delete some characters. She's not sure she understands why this is happening or how she can get the date she wants in the footer.

There is no actual formula that can put the last-saved date in a footer. Excel has no way (unlike Word) to put this tidbit of information there. There is a way you can do it, but the solution requires the use of a macro. The reason is because you are accessing system information—information outside of Excel itself—and that information can only be retrieved using a programming language such as VBA.

One approach is to add some code that runs whenever a workbook is saved. The code would update the desired footer with the current date:

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

    ActiveWorksheet.PageSetup.RightFooter = _
      "Last Saved: " & Format(Date, "mmmm d, yyyy")
End Sub

This macro, which should be stored in the ThisWorkbook object for the workbook you want to affect, updates the footer for the currently active worksheet. If you want to affect all the worksheets in a workbook, then a small change to the macro is in order:

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

    For Each sht In Sheets
        sht.PageSetup.RightFooter = _
          "Last Saved: " & Format(Date, "mmmm d, yyyy")
    Next
End Sub

If today is December 12, 2011, then after running the macro (which is done automatically when saving), the right footers will all be set to "Last Saved: December 12, 2011".

You can also rely upon the file save date stored in Excel's built-in properties. The way you put that date into the footer is as follows:

Sub RightFooterLastSaved()
     ActiveSheet.PageSetup.RightFooter = _
       ActiveWorkbook.BuiltinDocumentProperties(12)
End Sub

The drawback to this macro is that you need to remember to run it periodically, so it is not quite as automatic as the previous approaches. You could, however, place the single line at the heart of the macro into the Workbook_BeforePrint event handler.

There is another approach you can use. This one involves requesting from Windows the actual date and time a file was saved.

Private Sub Workbook_Open()
    Dim sTemp As String
    Dim sht As Worksheet

    sTemp = FileDateTime(ActiveWorkbook.FullName)
    sTemp = "Last Saved: " & sTemp
    For Each sht In Sheets
        sht.PageSetup.RightFooter = sTemp
    Next sht
End Sub

This macro is designed to run whenever a workbook is first opened—it is saved as the Workbook_Open procedure of the ThisWorkbook object. The workhorse of the macro is the line that calls the FileDateTime function. This function can be used to determine the date and time any file was saved. It requires a full path name of a file, which is supplied by the FullName property of the ActiveWorkbook object. This date and time is then placed in the right footer of all the worksheets in the workbook.

Remember, as well, that the limit of what you can place into each section of the header or footer is approximately 250 characters. So if you adjust the macros to add more information to the right portion of the footer, make sure that it doesn't add up to that many characters, or you may have problems with the macro.

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

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

Finding the Nth Root of a Number

Finding a square root is easy because Excel provides a worksheet function for that purpose. Finding a different root may not ...

Discover More

Grabbing a Screen Shot

There are times that a picture is worth a thousand words. When you need to capture a picture of what is on your screen, ...

Discover More

Easily Backing Up AutoText Entries

Many people use AutoText to enhance their use of Word. If you've invested significant time in customizing AutoText to make it ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

MORE EXCELTIPS (RIBBON)

Adding Ampersands in Headers and Footers

Add an ampersand to the text in a header or footer and you may be surprised that the ampersand disappears on your printout. ...

Discover More

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
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 for this tip:

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. 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 7 + 8?

2017-01-10 14:31:58

Mike R

(I haven't tried yet, but...) Does this work only for the workbook for which I insert this macro? Can it be tweaked up - to perhaps work like an add-in - for EACH workbook I open then subsequently save? That would be truly helpful...


2015-12-24 09:45:56

Glenn Case

PReinie:

ThisWorkbook and the code pages for each worksheet are used for Event macros, which only run when triggered by some Excel event. In this case, the event is triggered when the workbook is opened, as indicated by the macro name, Workbook_Open(). To see a list of event triggers, open the VB editor and double-click on ThisWorkbook to open the code window. There are two fields above the code window; in the left one, select Workbook. Click on the right one, and you will get a list of event macros which are available for the Workbook. In the list you will find Before_Close and Before_Save, the events you were enquiring about. You can do the same with the code windows for each worksheet. To reveal those pages, right-click the worksheet tab and select View Code.

A google search on Event code should get you more info than you can handle on this subject.


2015-12-22 12:15:28

PReinie

Does Excel (2007) just run every macro in ThisWorkbook at some time?

How do you control causing an action at opening or saving a workbook as I'm not seeing anything showing up in my footer?
(I'm comparing with Word which can have actionable triggers at opening or closing or saving, etc.)

Do I have to put something in the footer as a placeholder for the saved date? It looks like the macro should do it without anything special other than saving the file.


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.

Links and Sharing
Share