Graphic Members
Use the Graphic object to add pictures to headers and footers through the PageSetup object. Use the PageSetup object’s CenterFooterPicture, CenterHeaderPicture, LeftFooterPicture, LeftHeaderPicture, RightFooterPicture, or RightHeaderPicture methods to get a reference to this object. The Graphic object has the following members, most of which are shared by the PictureFormat object. Unique, key members (shown in bold) are covered in the following reference section:
|
Application |
Brightness |
|
ColorType |
Contrast |
|
Creator |
CropBottom |
|
CropLeft |
CropRight |
|
CropTop |
|
|
Height |
|
|
Parent |
Width |
To add a graphic to a header or footer in code:
Use one of the
PageSetupobject’s header or footer picture methods to get a reference to theGraphicobject.Set the
Filenameproperty of theGraphicobject.Set the
PageSetupobject’s corresponding header or footer property to&G.
The following code demonstrates adding a bitmap to the center footer of the active worksheet and previews the result before printing:
Sub AddFooterGraphic( )
Dim ws As Worksheet, ps As PageSetup
Set ws = ActiveSheet
Set ps = ws.PageSetup
ps.CenterFooterPicture.Filename = _
ThisWorkbook.Path & "\wombatright.bmp"
ps.CenterFooter = "&G"
ws.PrintOut , , , True
End SubTo remove the graphic from the header or footer, remove the &G from the header or footer as shown here:
Sub RemoveFooterGraphic( )
Dim ws As Worksheet
Set ws = ActiveSheet
ws.PageSetup.CenterFooter = ""
End SubBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access