Reputation: 9
I am trying to insert header with picture and some texts by copying values from 2 different cells. I tried googling but somehow what I manage to get is the image only appears when in the printable mode but not in the workbook. Below is the code that I've tried.
Dim ws As Worksheet
Set ws = Worksheets("Output")
With ws.PageSetup
.CenterFooterPicture = "&G" 'Specifies that you want an image in your footer
.CenterFooterPicture.Filename = "C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"
End With
While a new workbook is being generated, the header with picture and the texts should be inside as well
Upvotes: 0
Views: 121
Reputation: 49998
The CenterFooterPicture
documentation notes:
It is required that "&G" is a part of the
CenterFooter
property string in order for the image to show up in the center footer.
Similar to the example the documentation provides, try:
Dim ws As Worksheet
Set ws = Worksheets("Output")
With ws.PageSetup
.CenterFooterPicture.Filename = "C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"
End With
ws.PageSetup.CenterFooter = "&G" 'Specifies that you want an image in your footer
EDIT:
Based on the comment that you want the image in the left header, try this similar snippet:
Dim ws As Worksheet
Set ws = Worksheets("Output")
With ws.PageSetup
.LeftHeaderPicture.Filename = "C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"
End With
ws.PageSetup.LeftHeader = "&G"
Upvotes: 1