Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Last Saved Date in a Footer

Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Last Saved Date in a Footer.

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 (2190) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Last Saved Date in a Footer.

Related Tips:

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

Michael (Micky) Avidan    25 May 2015, 13:22
@Robert Fletcher,
Try to save the workbook type as: "Macro enabled" (XLSM File extension).
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2015)
ISRAEL
Robert Fletcher    24 May 2015, 21:05
I am trying to put the date my Excel for Max was last saved in the footer. I followed your example. I am not knowledgeable with macros. I was to get on the developer tab. I selected Editor and then selected the ThisWorkbook. I got a blank VBA input space and entered the following from your website:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
   Cancel As Boolean)
   ActiveWorksheet.PageSetup.RightFooter = _
   "Last Saved: " & Format(Date, "mmmm d,yyyy")
End Sub

I then proceeded to save the workbook. An error message always appears "Visual Basic Macros will be removed if you save the file in this format." I am then directed to bug theVBA file.

What am I doing wrong? Why do I always get this error message even when I think I have removed the macro? Please help

Bob
Andrea    23 Sep 2013, 12:13
Thanks so much! I've tried 3 codes now, and this is the only one that worked - perhaps because I wasn't told to open he "this workbook" section(using Excel 2010):

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
awyatt    03 May 2013, 13:14
Not really. (Although you can click the link at the end of the article to see this tip on the site for later versions of Excel.)

I suspect you aren't putting the macros in the ThisWorkbook area as you must. Any macro that begins with "Workbook_" must be placed in the ThisWorkbook area. In the VBA Editor, use the Project Explorer to double-click the ThisWorkbook object for the workbook in which you are working. This action (double-clicking) displays a code window. It is within this code window that those macros beginning with "Workbook_" must be placed.

-Allen
Michael Mercier    03 May 2013, 12:50
I am running Excel 2007. I copy pasted this program as described. the first program for active worksheet and also tried the seceond program for all sheets.
Neither one puts anything into the footer.
Is excel 2007 different?
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.