Microsoft Office Tutorials and References
In Depth Information
Printing the Contents of a Cell in a Header or Footer
3. Type the following macro (see Figure 191-2):
Private Sub Workbook_BeforePrint(Cancel As Boolean)
With ActiveSheet.PageSetup
.CenterHeader = Sheets(“Sheet1”).Range(“A1”).Text’
End With
End Sub
Figure 191-2: This macro is executed before the workbook is printed.
This macro is executed whenever the workbook is printed. The macro copies the contents of cell
A1 (on Sheet1) into the center header. You can, of course, adjust the sheet name or range address
so that the header displays the contents of a different cell.
To put the cell contents in a different header or footer position, substitute one of the following
names for CenterHeader:
h LeftHeader
h RightHeader
h LeftFooter
h CenterFooter
h RightFooter
Unfortunately, Excel 2010 does not display the new header or footer when the workbook is
If your workbook has an XLSX extension, you need to resave it with an XLSM
extension. Otherwise, Excel will discard the macro.
Search JabSto ::

Custom Search