dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,375
- Office Version
- 365
- 2016
- Platform
- Windows
I have a sub that is meant to load a custom header and footer
And also, part of the same module
It used to work fine so I have no idea why it isn't working now.
I try to run it now and I get the error of Application defined or object defined error. I press debug and this line in the second procedure is highlighted:
Could someone help me work out the problem please?
VBA Code:
Sub Wes_header_footer()
Dim printWorksheet As Worksheet, logoShape As Shape, tempImageFile As String
Dim footshape As Shape, ACAWorksheet As Worksheet
'The worksheet on which the print page setup will apply
Set printWorksheet = ThisWorkbook.Worksheets("CSS_quote_sheet")
'Set ACAWorksheet = ThisWorkbook.Worksheets("ACA_Quoting")
'The sheet location and name of shape to be used in page setup
Set logoShape = ThisWorkbook.Worksheets("sheet2").Shapes("ImgWestHeader")
Set footshape = ThisWorkbook.Worksheets("sheet2").Shapes("ImgWestFooter")
'Save the shape as a temporary image
tempImageFile = Environ("temp") & "\image.jpg"
Save_Object_As_Picture logoShape, tempImageFile
With printWorksheet.PageSetup
.CenterHeaderPicture.fileName = tempImageFile
.CenterHeader = "&G"
End With
Kill tempImageFile
tempImageFile = Environ("temp") & "\image.jpg"
Save_Object_As_Picture footshape, tempImageFile
With printWorksheet.PageSetup
.CenterFooterPicture.fileName = tempImageFile
.CenterFooter = "&G"
End With
Kill tempImageFile
Worksheets("CSS_quote_sheet").Activate
Range("B7").Value = "Ang Wes"
End Sub
And also, part of the same module
VBA Code:
Private Sub Save_Object_As_Picture(saveObject As Object, imageFileName As String)
Dim temporaryChart As ChartObject
Application.ScreenUpdating = False
saveObject.CopyPicture xlScreen, xlPicture
Set temporaryChart = ActiveSheet.ChartObjects.Add(0, 0, saveObject.Width + 1, saveObject.Height + 1)
With temporaryChart
.Activate
.border.LineStyle = xlLineStyleNone 'No border
.Chart.Paste
.Chart.Export imageFileName
.Delete
End With
Application.ScreenUpdating = True
Set temporaryChart = Nothing
End Sub
It used to work fine so I have no idea why it isn't working now.
I try to run it now and I get the error of Application defined or object defined error. I press debug and this line in the second procedure is highlighted:
VBA Code:
Set temporaryChart = ActiveSheet.ChartObjects.Add(0, 0, saveObject.Width + 1, saveObject.Height + 1)
Could someone help me work out the problem please?