Formatting and VBA Codes For Headers and Footers - Microsoft Docs
Formatting and VBA Codes For Headers and Footers - Microsoft Docs
In this article
Example
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).
&"fontname" Prints the characters that follow in the specified font. Be sure to include the
double quotation marks.
1 of 3 12/29/2020, 2:46 PM
Formatting and VBA codes for headers and footers | Microsoft Docs https://docs.microsoft.com/en-us/office/vba/excel/concepts/workbooks-a...
&nn Prints the characters that follow in the specified font size. Use a two-digit
number to specify a size in points.
&color Prints the characters in the specified color. User supplies a hexadecimal color
value.
&"+" Prints the characters that follow in the Heading font of the current theme. Be
sure to include the double quotation marks.
&"-" Prints the characters that follow in the Body font of the current theme. Be
sure to include the double quotation marks.
&K xx. S nnn Prints the characters that follow in the specified color from the current
theme.
S nnn specifies the shade (tint) of that theme color. Specify S as + to produce
a lighter shade; specify S as - to produce a darker shade.
If the values that specify the theme color or shade are not within the
described limits, Excel will use the nearest valid value.
2 of 3 12/29/2020, 2:46 PM
Formatting and VBA codes for headers and footers | Microsoft Docs https://docs.microsoft.com/en-us/office/vba/excel/concepts/workbooks-a...
Example
The following code shows how formatting and VBA codes can be used to modify the
header information and appearance.
VB Copy
Sub Date_Time()
ActiveSheet.PageSetup.CenterHeader = "&D &B&ITime:&I&B&T"
End Sub
Yes No
3 of 3 12/29/2020, 2:46 PM