Hattie
New Member
- Joined
- Oct 7, 2020
- Messages
- 18
- Office Version
- 365
- Platform
- 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
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