Public Sub Setup_Page_Header_Different_First_Page()
Dim shpFirstPage As Shape, shpOtherPages As Shape
Dim tempImageFile1 As String, tempImageFile2 As String
Set shpFirstPage = ActiveSheet.Shapes(1)
Set shpOtherPages = ActiveSheet.Shapes(2)
'Save the shapes as temporary image files
tempImageFile1 = Environ("temp") & "\image1.bmp"
Save_Object_As_Bitmap shpFirstPage, tempImageFile1
tempImageFile2 = Environ("temp") & "\image2.bmp"
Save_Object_As_Bitmap shpOtherPages, tempImageFile2
'Add the images to the first page header and other pages
With ActiveSheet.PageSetup
.DifferentFirstPageHeaderFooter = True
.FirstPage.CenterHeader.Picture.Filename = tempImageFile1
.FirstPage.CenterHeader.Text = "&G"
.CenterHeaderPicture.Filename = tempImageFile2
.CenterHeader = "&G"
End With
Kill tempImageFile1
Kill tempImageFile2
End Sub
Private Sub Save_Object_As_Bitmap(saveObject As Object, imageFileName As String)
'Save an object in bitmap format.
'Arguments
'saveObject - any object in the CopyPicture method's 'Applies To' list, for example a Range or Shape
'imageFileName - the .bmp, .gif, .jpg, or .png file name (including folder path if required) the object will be saved as
Dim temporaryChart As ChartObject
saveObject.CopyPicture xlScreen, xlBitmap
Set temporaryChart = ActiveSheet.ChartObjects.Add(0, 0, saveObject.Width + 6, saveObject.Height + 6)
With temporaryChart
.Activate 'Required, otherwise image is blank with Excel 2016
.Border.LineStyle = xlLineStyleNone 'No border
.Chart.Paste
.Chart.Export imageFileName
.Delete
End With
Set temporaryChart = Nothing
End Sub