Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Assigning a Macro to a Keyboard Combination
Hiding Rows Based on a Cell Value
There may be times when you want your header or footer to contain the date of the last time that your workbook was saved. Normally, this is not information you can set in Excel. However, you can use the following macro to force the information into the proper place:
Sub MyFooter()
Dim mh As String
On Error Resume Next
mh = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
If Err = 440 Then
Err = 0
mh = ActiveWorkbook.BuiltinDocumentProperties("Creation Date")
If Err = 440 Then
Err = 0
mh = "Not Set"
End If
End If
mh = Left(mh, 8)
ActiveSheet.PageSetup.LeftFooter = "Saved: " & mh
End Sub
There are a number of items to note in this macro. First of all, it attempts to determine the last date (and time) that the workbook was saved. If that information cannot be determined, then it extracts the date it was created. Finally, if that cannot be found, then it sets the footer to "Not Saved."
Notice that there is some error handling done in this macro. The reason is that Excel will return an error if a particular document property (BuiltinDocumentProperty in this case) is not set. The error needs to be intercepted and handled, which is done here.
You should note that this macro, once run, will set the left footer to the desired information. That information will not change again until you run the macro again. Thus, if you always want an up-to-date date in the footer, then you should either run the macro periodically (perhaps right before printing), or set it up to run whenever you open your document.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2055) applies to Microsoft Excel versions: 97 2000 2002 2003
Got the Time? Understanding the ins and outs of working with times and dates can be confusing. Remove the confusion--ExcelTips: Times and Dates is an invaluable resource for learning how best to work with times and dates.