![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Mar 2002
Posts: 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 |
|
|
|
|
|
#2 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
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
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
|
|
|
|
|
|
#3 |
|
New Member
Join Date: Mar 2002
Posts: 48
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|