dpaton05
Well-known Member
- Joined
- Aug 14, 2018
- Messages
- 2,392
- Office Version
- 365
- 2016
- Platform
- Windows
I have a procedure that runs
and when it gets to the save_object_as_picture procedure, the following will run,
but the code will halt on the following line
The procedure copies a picture from sheet2 and puts it at the top of CSS_quote_sheet.
It used to work and I am not sure why it now gives me an application defined or object defined error.
Can someone help me please?
VBA Code:
Sub Western_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 = "AngW"
End Sub
and when it gets to the save_object_as_picture procedure, the following will run,
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
but the code will halt on the following line
VBA Code:
Set temporaryChart = ActiveSheet.ChartObjects.Add(0, 0, saveObject.Width + 1, saveObject.Height + 1)
The procedure copies a picture from sheet2 and puts it at the top of CSS_quote_sheet.
It used to work and I am not sure why it now gives me an application defined or object defined error.
Can someone help me please?