Raptor776
Raptor776

Reputation: 190

Microsoft Excel copy paste to Powerpoint, both files crashing

I have the following VBA code where I am copying an excel range to Powerpoint. I have played around with adding various delays to ensure the copy paste command is executed correctly, however the file crashed regardless of the delay.

I currently have a Do loop and the file still crashes without exiting the loop. If somebody could provide some guidance, it will be greatly appreciated

rng.Copy
DoEvents

Do
    On Error Resume Next
    mySlide.Shapes.PasteSpecial ppPasteBitmap  '2 = ppPasteEnhancedMetafile
    Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
    'Set position:
    myShape.Left = 50
    myShape.Top = 141
    myShape.Width = 620
    myShape.Height = 320

    If Err.Number = 0 Then
        On Error GoTo 0
        Exit Do
    End If
Loop

Upvotes: 0

Views: 344

Answers (1)

Shai Rado
Shai Rado

Reputation: 33672

Assuming you declared and set-up mySlide correctly to your desired slide, use the following code:

Dim myShape                             As Object

Set myShape = mySlide.Shapes.PasteSpecial(ppPasteBitmap)

'Set position:
myShape.Left = 50
myShape.Top = 141
myShape.Width = 620
myShape.Height = 320

Upvotes: 1

Related Questions