This documentation is archived and is not being maintained.

Formatting and VBA Codes for Headers and Footers

Office 2007

The following special formatting and Visual Basic for Applications (VBA) codes can be included as a part of the header and footer properties (LeftHeader, CenterHeader, RightHeader, LeftFooter, CenterFooter, and RightFooter).

Format codeDescription
&LLeft aligns the characters that follow.
&CCenters the characters that follow.
&RRight aligns the characters that follow.
&ETurns double-underline printing on or off.
&XTurns superscript printing on or off.
&YTurns subscript printing on or off.
&BTurns bold printing on or off.
&ITurns italic printing on or off.
&UTurns underline printing on or off.
&STurns strikethrough printing on or off.
&"fontname"Prints the characters that follow in the specified font. Be sure to include the double quotation marks.
&nnPrints the characters that follow in the specified font size. Use a two-digit number to specify a size in points.
&colorPrints the characters in the specified color. User supplies a hexidecimal color value.
VBA codeDescription
&DPrints the current date.
&TPrints the current time.
&FPrints the name of the document.
&APrints the name of the workbook tab.
&PPrints the page number.
&P+numberPrints the page number plus the specified number.
&P-numberPrints the page number minus the specified number.
&&Prints a single ampersand.
&NPrints the total number of pages in the document.
&ZPrints the file path.
&GInserts an image.


The following code shows how formatting and VBA codes can be used to modify the header information and appearance.

Sub Date_Time()
    ActiveSheet.PageSetup.CenterHeader = "&D  &B&ITime:&I&B&T"
End Sub