I am using Excel 2007 with a workbook that has many sheets. I need to have the date when the worksheet was last saved – in the footer. I was able to find the following:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
With ws.PageSetup
.LeftFooter = "Last Save Time: &T"
.RightFooter = "Last Save Date: &D"
End With
Next ws
Set ws = Nothing
End Sub
This changes every worksheet. I need it to only change a sheet that has been edited (so each worksheet can have a different date).
Is this even possible? Should I use a cell instead of a footer? Or do I have to create multiple workbooks?
Thanks!
As Remnant suggested, best approach would be to utilize the
Worksheet_Changeevent. That means, you need this VBA codein every of your worksheets. This event is only raised when you change a cells content, not when you change the selection, so it may be what you want.
Remnant also wrote that this would be a “pain to set up” if you have many worksheets. I think that depends on what you call “many”. For up to 20~40 worksheets, the code from above can be easily copied manually to every sheet in a few minutes.
If you already have a workbook and a lot (say, more that 40) sheets, then it may be a good idea to add the code programmatically. Add a separate module to your workbook, containing this code, and run it once:
This will add the “Worksheet_Change” event from above to the code section of every sheet.