have a problem with my code when I'm trying to copy some data from excel to PowerPoint using Excel VBA.
The problem is that it sometimes work properly and with no error but sometimes its crashes and stops during the run.
Sub Test()
Set PowerPointApp = CreateObject("PowerPoint.Application")
Set ppApp = New powerpoint.Application
ppApp.Visible = True
DestinationPPT = "C:\Users\Saeed\Desktop\edit vba\test.pptx"
Set ppPres = PowerPointApp.Presentations.Open(DestinationPPT)
Sheets("Slide3").Activate
Sheets("Slide3").Range("A2").Select
Selection.Copy
ppApp.Activate
ppPres.Slides(3).Select
ppApp.Windows(1).View.Paste
Set shp = ppPres.Slides(3).Shapes(ppPres.Slides(3).Shapes.Count)
shp.Left = 17
shp.Top = 90
ppApp.Windows(1).Selection.Unselect
ppPres.SaveAs "C:\Users\Saeed\Desktop\edit vba" & FileName, ppSaveAsPDF
ppPres.Close
ppApp.Quit
Set ppt = Nothing
I skipped the dim parts and some unimportant ones.
But here is the problem : it always crashes in
ppApp.Windows(1).View.Paste
and I don't know how to fix it since it sometimes runs perfect and sometimes gives me error on that part ! I tried to use On error Goto but nothing changed. It would be appreciated to help me out in this wierd problem.