Hi, I have a macro that generates PowerPoint slides which a bunch of different things from Excel. I have a total of about 50 Slides to generate, often at around 20 slides the code will crash and give a runtime error. When it crashes its always got something to do with this section of the code where it copies and pastes the picture from Excel to PowerPoint.
The error either occurs on the .CopyPicture or the .Paste lines.
Currently I've tried the following and still have errors:
The only thing I can think of is it being a memory issue, all my variables are either inside functions or subs and the only objects that are set in the main sub are all set = nothing at the end of the sub.
Any help would be great. Thanks
[TABLE="width: 1000"]
<tbody>[TR]
[TD]' This Sub copies a picture from Excel, pastes to PowerPoint, resizes and re positions the selection.
Sub CopyToPowerPoint(PictureToCopy As String, TopPosition As Double, LeftPosition As Double, HeightSize As Double, WidthSize As Double)
' If only resizing an image, skips the copy/paste
If PictureToCopy = "ResizeOnly" Then
GoTo SkipCopy
End If
wb.Sheets("Dashboard").ChartObjects(PictureToCopy).CopyPicture
ppPres.Slides(1).Shapes.Paste
SkipCopy:
ppApp.Visible = msoTrue
With ppApp.Windows(1).Selection
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Top = TopPosition * cmtopixel
.ShapeRange.Left = LeftPosition * cmtopixel
.ShapeRange.Width = WidthSize * cmtopixel
.ShapeRange.Height = HeightSize * cmtopixel
End With
End Sub[/TD]
[/TR]
</tbody>[/TABLE]
The error either occurs on the .CopyPicture or the .Paste lines.
Currently I've tried the following and still have errors:
- CutCopyMode = False right after the paste.
- ScreenUpdating both True and False
- WindowMinimized both True and False
The only thing I can think of is it being a memory issue, all my variables are either inside functions or subs and the only objects that are set in the main sub are all set = nothing at the end of the sub.
Any help would be great. Thanks
[TABLE="width: 1000"]
<tbody>[TR]
[TD]' This Sub copies a picture from Excel, pastes to PowerPoint, resizes and re positions the selection.
Sub CopyToPowerPoint(PictureToCopy As String, TopPosition As Double, LeftPosition As Double, HeightSize As Double, WidthSize As Double)
' If only resizing an image, skips the copy/paste
If PictureToCopy = "ResizeOnly" Then
GoTo SkipCopy
End If
wb.Sheets("Dashboard").ChartObjects(PictureToCopy).CopyPicture
ppPres.Slides(1).Shapes.Paste
SkipCopy:
ppApp.Visible = msoTrue
With ppApp.Windows(1).Selection
.ShapeRange.LockAspectRatio = msoFalse
.ShapeRange.Top = TopPosition * cmtopixel
.ShapeRange.Left = LeftPosition * cmtopixel
.ShapeRange.Width = WidthSize * cmtopixel
.ShapeRange.Height = HeightSize * cmtopixel
End With
End Sub[/TD]
[/TR]
</tbody>[/TABLE]