BeforePrint Event

jfuoti

New Member
Joined
Mar 26, 2002
Messages
48
I have the following code in the BeforePrint section of VBE. The function works correctly when I print from the worksheet, but does not update the header when I print from a macro - even though it is accessing the event (I checked with debugger) Anyone have any ideas to correct this? Thanks!

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim Title
Title = ActiveSheet.Name & " " & Format(Right(ActiveWorkbook.Names("DataDate").Value, 5), "mm/dd/yyyy")
With ActiveSheet.PageSetup
.LeftFooter = ActiveWorkbook.FullName
.CenterHeader = Title
End With
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You could split this macro out to call the procedure from a normal module. Something along the lines as follows:

In the this workbook module:
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.Run ("setUp")
End Sub

And in normal modules:
Code:
Private Sub setUp()
Dim Title
Title = ActiveSheet.Name & " " & Format(Right(ActiveWorkbook.Names("DataDate").Value, 5), "mm/dd/yyyy")
With ActiveSheet.PageSetup
.LeftFooter = ActiveWorkbook.FullName
.CenterHeader = Title
End With
End Sub

Sub Othermacro()
Application.Run ("setUp")
ActiveSheet.PrintOut
End Sub

Hopefully this helps.
 
Upvote 0
Thanks Nate, I went with code in a normal module to put the header & footer on all sheets before I print any:

For Each Worksheet In Worksheets
Dim Title
Title = "&B &14" & Worksheet.Name & " " & Format(Right(ActiveWorkbook.Names("DataDate").Value, 5), "mm/dd/yyyy")
With Worksheet.PageSetup
.LeftFooter = ActiveWorkbook.FullName
.CenterHeader = Title
End With
Next Worksheet
 
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

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