sharifadabi
New Member
- Joined
- Nov 26, 2021
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hello, I have found this nice code here for inserting image from a sheet to header, but I have problem in using that for the first page:
Could you please help me?Public Sub Setup_Page_Header()
Dim shp As Shape
Dim tempImageFile As String
Set shp = ActiveSheet.Shapes("Picture 1")
'Save the shape as a temporary image file
tempImageFile = Environ("temp") & "\image.bmp"
Save_Object_As_Bitmap shp, tempImageFile
'Add the file to the page header
With ActiveSheet.PageSetup
FirstPage.CenterHeader.Picture.Filename = tempImageFile
.CenterHeader = "&G"
End With
Kill tempImageFile
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