ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automating Page Header (https://www.excelbanter.com/excel-programming/377972-automating-page-header.html)

steven

Automating Page Header
 
I have this in the before print:

vDate = Range("C4").Value
vName = Range("C5").Value
ActiveSheet.PageSetup.LeftHeader = "Expense Report" & Chr(10) & vDate &
Chr(10) & vName

Question: How do I tell it only print the Header if Page Number is greater
than 1.

Thank you for your help.

Steven.

Martin Fishlock[_4_]

Automating Page Header
 
Steven,

To the best of my knowledge it is not possible to set a flag (similar to
word) to print a different header on the first page.

But you can, as you rightly say, use the beforeprint event as follows:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
On Error GoTo resume_pos
Dim sz_Header As String
Dim vDate As Variant
Dim vName As Variant

Cancel = False
Application.EnableEvents = False
vDate = ActiveSheet.Range("C4").Value
vName = ActiveSheet.Range("C5").Value
sz_Header = "Expense Report" & Chr(10) & vDate & Chr(10) & vName

ActiveSheet.PageSetup.LeftHeader = ""
ActiveSheet.PrintOut From:=1, To:=1
ActiveSheet.PageSetup.LeftHeader = sz_Header
ActiveSheet.PrintOut From:=2
resume_pos:
Application.EnableEvents = True
End Sub

You need to disable the enableevents while the operation is performed and
reset it afterwards.

If you are debuging the and stop the code the enableevents is not reset so
itis useful to have the following macro to reset it:

Public Sub setenableeventstrue()
Application.EnableEvents = True
End Sub

--
HTHs Martin Fishlock


"Steven" wrote:

I have this in the before print:

vDate = Range("C4").Value
vName = Range("C5").Value
ActiveSheet.PageSetup.LeftHeader = "Expense Report" & Chr(10) & vDate &
Chr(10) & vName

Question: How do I tell it only print the Header if Page Number is greater
than 1.

Thank you for your help.

Steven.



All times are GMT +1. The time now is 02:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com