VBA project

GYR

New Member
Joined
Mar 27, 2012
Messages
2
Hello,

We are using Excel 2007.

I wanted to add the date of the last modification of the file to the printed pages, so I googled how to do it and found a useful answer on this from from 10 years ago. It said to press ALT+F11, then on the left side go under VBAProject, there go to ThisWorkbook and there paste the next code:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
For Each wk In Worksheets
With ActiveSheet.PageSetup
.LeftHeader = "Last Modified on " & ActiveWorkbook.BuiltinDocumentProperties.Item("Last Save Time")
.CenterHeader = ""
.RightHeader = "Printed on &D &T"
.LeftFooter = "&F &A"
.CenterFooter = ""
.RightFooter = "Page &P of &N"
End With
Next
End Sub

Then I saved it and closed. Like I said, it worked perfectly.

The problem is that when I open the file after closing it, it does not appear, and I have to paste the code again every time I open it. Not only is this not comfortable, it also counts as a modification, so even if I haven't changed the work sheets themselves, just wanted to open and print it, it shows today's date.

My question is, who to I save it permanently so it will remain always after the first time I created it?

While we're at it, if there's a way for that code to appear on every NEW Excel file I create automatically that would be great.

Thanks so much.

Gil
 
Last edited by a moderator:
You need to save the file in macro-enabled (xlsm) fomat. You should be getting a warning that you can't save the VBA project with an xlsx file.
 
Upvote 0
Hi Gil

Do you save the file down after you paste the code in (you need to)? And you must save the file as something other than a .xlsx (as these do not hold VBA code).

To include this in any new workbooks created, you need to create a new workbook and post the code into the ThisWorkbook module of this workbook, and then save this workbook as Book.xltm in your XLSTART folder (the location of which will vary according to your OS - do a Google search to identify where it will be).
 
Upvote 0
I saved it as xlsm and it seems to be working.
This is so efficient! Thank you all!
Gil.
 
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