Insert cell contents into header/footer

G

Guest

I would like to know how to insert the contents of a particular cell (in each
worksheet) into the header/footer for the corresponding worksheet.
 
B

Bob Phillips

Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
.LeftFooter = Range("A1").Value
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
 
G

Guest

I would like this routine to work for all worksheets in the workbook when the
"print entire workbook" selection is made. The routine below only does the
first worksheet footer when I print the entire workbook.
 
R

Ron de Bruin

You can loop through the sheets

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim wkSht As Worksheet
For Each wkSht In ThisWorkbook.Worksheets
wkSht.PageSetup.LeftFooter = wkSht.Range("A1").Value
Next wkSht
End Sub
 
G

Guest

Thanks, that works.

Ron de Bruin said:
You can loop through the sheets

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim wkSht As Worksheet
For Each wkSht In ThisWorkbook.Worksheets
wkSht.PageSetup.LeftFooter = wkSht.Range("A1").Value
Next wkSht
End Sub
 
R

Ron de Bruin

Yes

See how I use the font size here
http://www.rondebruin.nl/print.htm#Saved

Check out the VBA help for all formatting codes.
Look for "Formatting Codes for Headers and Footers"

You can use something like this :

.CenterFooter = "&8Page &P & of &N"
.RightFooter = "&8Last Saved : &B" & ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
.LeftFooter = "&8" & ActiveWorkbook.FullName & Chr(10) & "Sheetname : &B" & ActiveSheet.Name
 
G

Guest

Thanks, that worked.

Ron de Bruin said:
Yes

See how I use the font size here
http://www.rondebruin.nl/print.htm#Saved

Check out the VBA help for all formatting codes.
Look for "Formatting Codes for Headers and Footers"

You can use something like this :

.CenterFooter = "&8Page &P & of &N"
.RightFooter = "&8Last Saved : &B" & ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
.LeftFooter = "&8" & ActiveWorkbook.FullName & Chr(10) & "Sheetname : &B" & ActiveSheet.Name
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top