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

by Allen Wyatt
(last updated February 27, 2016)

10

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, and 2016. 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

Word Won't Start Right

Sometimes it seems that no matter what you do, you can't display Word on your screen. If this is the case, it could be ...

Discover More

Displaying Actual Font Faces

Want to see font samples as you contemplate which fonts to use in your document? Word provides an easy way to do this.

Discover More

Inserting Worksheet Values with a Macro

Macros are often used to process information in a worksheet. You may need your macro to change the values stored in ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Sequential Page Numbers Across Worksheets

How do you want your page numbers to appear on your printed worksheets? Chances are good that you want them to be ...

Discover More

Adding Graphics to a Header or Footer

Excel makes it easy to add graphics to a header or footer. Here's the steps to make it happen.

Discover More

Copying Headers and Footers

Need to copy headers and footers from one worksheet to another? How about from one workbook to another? Here are some ...

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}] 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 four minus 0?

2016-03-01 05:46:15

Manfred

@ Walter, should also work

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
ActiveSheet.PageSetup.LeftFooter = _
"Worksheet Last Changed: " & _
Format(Now, "dd-mmm-yyyy hh:mm") &_
vbLf & _
"by: " & Application.UserName
End Sub


2016-02-29 11:45:25

Derek Gerry

Walter, The code below will get the user name for you.

Declare Function wu_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
As Long
Function ap_GetUserName() As Variant

Dim strUserName As String
Dim lngLength As Long
Dim lngResult As Long

'-- Set up the buffer
strUserName = String$(255, 0)
lngLength = 255

'-- Make the call
lngResult = wu_GetUserName(strUserName, lngLength)

'-- Assign the value
ap_GetUserName = Left(strUserName, InStr(1, strUserName, Chr(0)) - 1)

End Function


2016-02-29 11:39:45

Michael (Micky) Avidan

@Abdul hamid,
In case Peter Atherton better understood your request, than I did, try the following macro (make sure you have at least 12 sheets in your Workbook):
-----------------
Sub NameSheets()
On Error Resume Next
For M = 1 To 12
Worksheets(M).Name = MonthName(M)
Next
End Sub
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-02-29 11:19:19

Peter Atherton

Abdul

I don't know what happened to the code, You do want to rname the sheets?

Sub NameSheets()
Dim i As Integer
Dim va As Variant
On Error GoTo 0
va = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", _
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
For i = 1 To Worksheets.Count
Worksheets(i).Name = va(i - 1) & format(Year(Now()), "-yy")
Next i
End Sub


2016-02-29 07:45:25

Walter A

I have a shared workbook with several named sheets, how would you change the macro to the last user and date? the user is unique to the computer and in code so their name doesn't actually appear.


2016-02-29 05:26:10

Michael (Micky) Avidan

@ABDUL HAMID,
If you prefer a Macro - try the following (change the value of the variable Num from 1-12):
Sub MonthsName()
Num = 5
MsgBox MonthName(Num)
End Sub
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-02-29 05:19:46

Michael (Micky) Avidan

@ABDUL HAMID,
Suppose you have the number 5 un cell A1.
In cell B1 type: =DATE(2016,A1,1) and custom format that cell as: mmmm.
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-02-28 19:52:18

Paul

Hi. I have a spreadsheet that is on a shared drive accessed by 1/2 dozen people, but the actual spreadsheet is not "shared" as such - i.e. only one person can open it at a time.
Is there a way to record who last saved the sheet?


2016-02-28 10:43:27

Peter Atherton

Abdul

Try this macro, it uses month short name and adds the last two digits of the year.

To change the names in the array fill the rest of the month''s name between each quotation.

To remove the year change the line Worksheets(i).Name = va(i - 1) & format(Year(Now()), "-yy")

to
Worksheets(i).Name = va(i - 1)

HTH


2016-02-27 05:35:22

ABDUL HAMID

How to convert Month in letter format mean if any excel sheet numbers are written like 1,2,3,4 etc and required to be converted in letter like January,February,March,April etc.


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.