How to have a custom date (YYYY) automatically updated in the footers (Excel 2010) upon opening a file

csauv

New Member
Joined
Jan 3, 2013
Messages
2
Dear All,

I would be grateful for your kind help. I am trying to have the year in the footers of all my Excel files to automatically update to the current year. To that effect, I have created the following macro:

Sub SetFooterAttributes()
For Each xWorksheet In ActiveWorkbook.Worksheets
xWorksheet.PageSetup.LeftFooter = & Format(Now, "YYYY")

Next xWorksheet

End Sub

I have applied this to 2012 files, thinking that I would not have to do it again when the files would be opened in 2013, as the code states 'now'. I was wrong!

How can I fix the footer so that the year is automatically updated please?

Thank you.

C.
 
Try this in the ThisWorkbook module

Code:
Private Sub Workbook_Open()
For Each xWorksheet In Me.Worksheets
    xWorksheet.PageSetup.LeftFooter = Format(Now, "YYYY")
Next xWorksheet
End Sub
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top