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

Filename

Height

LockAspectRatio

Parent

Width

To add a graphic to a header or footer in code:

  1. Use one of the PageSetup object’s header or footer picture methods to get a reference to the Graphic object.

  2. Set the Filename property of the Graphic object.

  3. Set the PageSetup object’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 Sub

To 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 Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.