Automatic Footers by default for all files VBA

Hattie

New Member
Joined
Oct 7, 2020
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Hello,

I would like all, existing and new excel files to print a footer by default.
I don't really want to edit every file I make to have the same footer every time.
Or re-edit all existing files...

So i thought VBA would be perfect for this job.

I have the following VBA code in the BeforePrint event in the "ThisWorkBook" object of an excel file [ VBAProject(Book1) ] and it works.

Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)

ActiveSheet.PageSetup.LeftFooter = "&8&""Arial""" & ActiveWorkbook.Name & " (" & ActiveSheet.Name & ")" & " (" & ActiveSheet.Range("B1:B1") & ")"

'Print Footer on charts if they exist
If Not (ActiveChart Is Nothing) Then
'Chart does exist
ActiveChart.PageSetup.LeftFooter = "&8&""Arial""" & ActiveWorkbook.Name & " (" & ActiveSheet.Name & ")" & " (" & ActiveSheet.Range("B1:B1") & ")"
End If

End Sub


I thought if i put this code into the BeforePrint event in the "ThisWorkBook" object of my VBAProject (Personal.XLSB)
then i would never have to look at it again and all existing and new files would print a footer by default because this code is in my personal.xlsb object.


but No

have i misunderstood the purpose of the personal object?

or have i failed to do something obvious?

thanks for any clues
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Your code uses the ActiveSheet and Activechart objects, so when you move your Workbook_BeforePrint event procedure to Personal.XLSB it will no longer work on the workbook you are trying to print. The code you move to your personal macro workbook should look something like this.
VBA Code:
'Locate this sub in PERSONAL.XLSB
Sub WorkbookPrintSetup()
    ActiveSheet.PageSetup.LeftFooter = "&8&""Arial""" & ActiveWorkbook.Name & " (" & ActiveSheet.Name & ")" & " (" & ActiveSheet.Range("B1:B1") & ")"

    'Print Footer on charts if they exist
    If Not (ActiveChart Is Nothing) Then
        'Chart does exist
        ActiveChart.PageSetup.LeftFooter = "&8&""Arial""" & ActiveWorkbook.Name & " (" & ActiveSheet.Name & ")" & " (" & ActiveSheet.Range("B1:B1") & ")"
    End If
End Sub

If you then paste Application.Run "'" & "PERSONAL.XLSB" & "'!WorkbookPrintSetup" into the "ThisWorkBook" code module of whatever workbook you want to set up the footer each time it is printed, it should work.
VBA Code:
'Locate in whatever workbook you want to set up the footer each time it is printed.
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Application.Run "'" & "PERSONAL.XLSB" & "'!WorkbookPrintSetup"
End Sub

(Tip: when posting code, please try to use 'code tags' to format the code as I have done above
it makes the code easier to read.)
 
Upvote 0
Solution
Thank you for this.

I have just got back from my Easter break.

I will give this a try.

Thanks agian and for the formatting tips.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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