ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Printing to header/footer programatically (https://www.excelbanter.com/excel-programming/327497-printing-header-footer-programatically.html)

Dean

Printing to header/footer programatically
 
I would like to be able to set a message to print in the footer/header of a
printed page depending on certain criteria in the spreadsheet.

Can someone suggest/advise how I could go about this.

Thanks in advance
Dean

Toppers

Printing to header/footer programatically
 
Dean,
A starter (from recording a macro as I added header and footer
to a worksheet). Change the header /footer sections as required according to
your selection criteria.

e.g

With ActiveSheet.PageSetup


If condition = criteria then
.LeftHeader=' .... whatever .."
else
.LeftHeader= " ... something else .."
End If
.....

End With



Range("A1:J32").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$32"

With ActiveSheet.PageSetup
' Header Sections .......
.LeftHeader = "My Left Header Section"
.CenterHeader = "My Centre Header Section"
.RightHeader = "My Right Header Section"
' Footer sections .....
.LeftFooter = "My Footer Left"
.CenterFooter = "My Footer Centre"
.RightFooter = "My Footer Right"

End With


HTH


"Dean" wrote:

I would like to be able to set a message to print in the footer/header of a
printed page depending on certain criteria in the spreadsheet.

Can someone suggest/advise how I could go about this.

Thanks in advance
Dean


Tom Ogilvy

Printing to header/footer programatically
 
You would want to put such code in the BeforePrint event. If you are not
familiar with events, see Chip Pearson's page on events

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy

"Toppers" wrote in message
...
Dean,
A starter (from recording a macro as I added header and

footer
to a worksheet). Change the header /footer sections as required according

to
your selection criteria.

e.g

With ActiveSheet.PageSetup


If condition = criteria then
.LeftHeader=' .... whatever .."
else
.LeftHeader= " ... something else .."
End If
....

End With



Range("A1:J32").Select
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$32"

With ActiveSheet.PageSetup
' Header Sections .......
.LeftHeader = "My Left Header Section"
.CenterHeader = "My Centre Header Section"
.RightHeader = "My Right Header Section"
' Footer sections .....
.LeftFooter = "My Footer Left"
.CenterFooter = "My Footer Centre"
.RightFooter = "My Footer Right"

End With


HTH


"Dean" wrote:

I would like to be able to set a message to print in the footer/header

of a
printed page depending on certain criteria in the spreadsheet.

Can someone suggest/advise how I could go about this.

Thanks in advance
Dean




Bob Phillips[_6_]

Printing to header/footer programatically
 
You can use VBA to set the BeforePrint to print the same footer


Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet
If .Range("A1") = "my value" Then
.PageSetup.LeftFooter = "Some text"
End If
End With
End Sub


'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dean" wrote in message
...
I would like to be able to set a message to print in the footer/header of

a
printed page depending on certain criteria in the spreadsheet.

Can someone suggest/advise how I could go about this.

Thanks in advance
Dean





All times are GMT +1. The time now is 10:47 PM.

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