Ivan, please answer about formulas in headers with VBA


Posted by Paul B on January 28, 2002 6:21 AM

I want to show what's in cell A1, in sheet1 in the header? I am using Excel '97. Thanks

Posted by Ivan F Moala on January 28, 2002 6:37 AM

Here's an example + your specific Q

Sub SetPrt()

Dim Lft As String, Ctr As String, Rght As String

'ActiveSheet.Range("A1") 'change A1 to your cell input
Lft = ActiveSheet.Range("A1") 'Left Text to print
'ActiveSheet.Range("B1") 'change B1 to your cell input
Ctr = ActiveSheet.Range("B1") 'Centre text to print
'ActiveSheet.Range("C1") 'change C1 to your cell input
Rght = ActiveSheet.Range("C1") 'Right Txt to Prt

With ActiveSheet.PageSetup
'## headers here ##
.LeftHeader = "&""Arial Black,Bold""&12" & Lft
.CenterHeader = "&""Arial Black,Bold""&8 " & Ctr
.RightHeader = "&""Times New Roman,Bold""&16" & Rght
'## footers here ##
.LeftFooter = "&""Arial Black,Bold""&12" & Lft
.CenterFooter = "&""Arial Black,Bold""&8 " & Ctr
.RightFooter = "&""Times New Roman,Bold""&16" & Rght
End With

ActiveWindow.SelectedSheets.PrintPreview

End Sub

'For your specific requirement;

Sub SetPrt_Header()

Dim sCentre As String

sCentre = ActiveSheet.Range("A1") 'Centre text to print

With ActiveSheet.PageSetup
'## header here ##
'Note change Font + Size to suit
'eg Arial 10 > .CenterHeader = "&""Arial""&10 " & Ctr
.CenterHeader = "&""Arial Black,Bold""&8 " & sCentre
End With

ActiveWindow.SelectedSheets.PrintPreview

End Sub


HTH

Ivan



Posted by Paul B on January 28, 2002 7:00 AM

Thanks (nt)