View Full Version : Solved: Syntax to "print in header"
DanOfEarth
05-27-2010, 05:34 AM
I know the code to put into the BeforePrint event handler to name a workbook the "filename" is:
Worksheets("Sheet1").PageSetup.LeftHeader = ActiveWorkbook.FullName
Instead I'm trying to put a cell content into the header off of worksheet "info", cell number C7
Worksheets("HAHA Letter").PageSetup.LeftHeader = Worksheets("Info").C7
Now I know that's not it...what would the syntax be?
DanOfEarth
05-27-2010, 05:50 AM
Forget it guys....I got it and it'll never work. It works normally, but I wanted it to print the headers when I printed to PDFs, and for some reason it doesn't pick it up.....unless anybody knows special code for THAT. What worked was....
Private Sub Workbook_BeforePrint(Cancel As Boolean)
' inserts the same header/footer in all worksheets
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Changing header/footer in " & ws.Name
With ws.PageSetup
.LeftHeader = Worksheets("Info").Range("C7").Text
.CenterHeader = "Loan 1 " & Worksheets("Info").Range("C23").Text
.RightHeader = "Loan 2 " & Worksheets("Info").Range("C33").Text
End With
Next ws
Set ws = Nothing
Application.StatusBar = False
End Sub
Bob Phillips
05-27-2010, 07:03 AM
Why don't you insert headings into the sheets when you open the workbook, using the workbook open event?
DanOfEarth
05-27-2010, 07:56 AM
OMG!
I didn't think about that...it's works brilliantly!
Thank you thank you.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.