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.
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!
Do you want to change the headers and footers that appear on different pages of your printout? Here's how you can get ...
Discover MoreWhen printing a worksheet, you may want to have the footer different on the first page of your document than it is on ...
Discover MoreExcel won't let you place a formula directly into a footer. You can, however, create a simple macro that will produce the ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2021 Sharon Parq Associates, Inc.
Comments