Personal.xlxs macro, BeforeSave event, how to apply to current workbook?

mcsinfl

New Member
Joined
May 4, 2011
Messages
4
I have the following macro to insert the path\filename\sheet into all sheets in a workbook. I would like to be able to automatically run the code whenever I save or print any active workbook. Can anyone help please?


Sub PathinFooter()

Dim WS_Count As Integer
Dim I As Integer
WS_Count = ActiveWorkbook.Worksheets.Count

For I = 1 To WS_Count
Sheets(I).Select

With ActiveSheet.PageSetup
.RightFooter = "&6&Z&F\&F\&A"
End With

Next I

Sheets(1).Select

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
use ThisWorkbook module

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'your code
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'your code
End Sub
 
Upvote 0
Thank you, but won't I then have to put this code in each workbook that I use? If so, I'm hoping to avoid that step.

Mark

use ThisWorkbook module

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
'your code
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'your code
End Sub
 
Upvote 0
I am not sure if it is possible. You may want to save your sub into your personal macro workbook and run it when you need to apply it to an active workbook.
 
Upvote 0
thanks, much appreciated. I was trying to avoid having to apply to the active workbook-as I get older my memory isn't what it used to be. Plus I often open workbooks other people created and this would automagically update those workbooks as well.


I am not sure if it is possible. You may want to save your sub into your personal macro workbook and run it when you need to apply it to an active workbook.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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