I am trying to copy a table from Excel and paste as an image to PowerPoint.
For some reason, the copy/paste methods error out about 1 in 10 attempts to run the code.
Any help would be greatly appreciated.
Here is the section of the code that is causing the errors (it's quite a long script in total):
Here is the error handling:
I am using Excel 2013 and Windows 10.
I can provide the full code if needed, but I cannot provide the data as it is proprietary.
For some reason, the copy/paste methods error out about 1 in 10 attempts to run the code.
- I added GoTo error handling but the code seems to be ignoring it.
- On the line "Graphic.Range("A1:AC102").CopyPicture" I receive 1004 errors.
- On the line "mySlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile" I receive -2147188160 (80048240) errors.
- I also tried adding a wait time to see if the file speed was causing the error, to no avail.
- I have searched the net and all the forums and cannot find the resolution to my issue.
Any help would be greatly appreciated.
Here is the section of the code that is causing the errors (it's quite a long script in total):
Code:
'Set PowerPoint Variables
Set PPTApp = CreateObject("PowerPoint.Application")
Set PPTPres = PPTApp.Presentations.Open(PPTTempLoc & PPTTemp)
PPTApp.Visible = True
Set mySlide = PPTPres.Slides(1)
'Slow down the code to prevent errors in copy method
Application.Wait (Now + TimeValue("0:00:01"))
'Copy Table from Excel
On Error GoTo 999 'handles errors in copy/paste method
Graphic.Range("A1:AC102").CopyPicture
'Slow down the code to prevent errors in paste method
Application.Wait (Now + TimeValue("0:00:01"))
'Paste Table in PowerPoint
mySlide.Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
'Reset error handling
On Error GoTo 0
Here is the error handling:
Code:
999:
'If error, repeat copy and resume
If Err.Number <> 0 Then
Graphic.Range("A1:AC102").CopyPicture
On Error Resume Next
End If
I am using Excel 2013 and Windows 10.
I can provide the full code if needed, but I cannot provide the data as it is proprietary.