PowerPoint crashes when running VBA code

Anonymous
2019-03-13T13:58:30+00:00

Hello,

I've got an Excel macros that runs an Excel model several times with different assumptions and copies the resulting charts/tables/text into a powerpoint presentation. 

The macros works fine most of the time however sometimes it freezes or crashes. 

When it freezes, it stops copying shapes/charts etc into powerpoint. It doesn't show any error message. 

When it crashes, PowerPoint just stops working and an error message appears. 

I tried to do some troubleshooting and it appears that the problem is in PowerPoint itself rather than the code. It seems that Powerpoint sometimes just refuses to paste the shape even though it's in the clipboard. I tried adding an additional loop that copies and pastes from the start if pasting takes too long but it only made it crash more often. 

I'd say it freezes 10-20% of the time and crashes 5-10% of the time - not too often but still extremely annoying. I find that rebooting the computer helps a bit but doesn't completely solve the problem. It also appears that the probability of the error  depends on the length of the code - i.e. if it's only a few shapes, it works fine, if it's 400+ shapes, it will crash at some point 

The code is quite standard for this type of task. I added several delays/checks to avoid the "clipboard is empty" problem. 

Case "TableCopy"

Sheets("Internal - to hide").Calculate

Sheets("Internal - to hide").Range(setrng).Copy

Do 

DoEvents

Loop until Not (IsClipboardEmpty) 

pslide.Shapes.Paste

Do '<~~ wait completion of paste operation

    DoEvents

Loop Until pslide.Shapes.Count > shapecount

With pslide.Shapes.Item(pslide.Shapes.Count)

 .Left = Left_start + (Scenarionum - 1) * Left_Increment 'change the number for desired x position

 .Top = Top_start + (Scenarionum - 1) * Top_increment 'change the number for desired y position

'  .LinkFormat.BreakLink

End With

[Moved from  Office/PowerPoint/Windows 10/Office 365 for business]

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. John Korchok 224.5K Reputation points Volunteer Moderator
    2019-03-14T14:37:16+00:00

    Sorry, in your most recent post, you say that you can resume the macro by pasting the last shape, but in the post before, you say that PowerPoint has crashed by that time. If PowerPoint had actually crashed, it seems you would have lost the file and not be able to resume. If PowerPoint hasn't crashed, then it means it's refusing the call to serve the OLE request.

    0 comments No comments
  2. Anonymous
    2019-03-14T14:59:45+00:00

    As I said it either crashes or hangs. 

    When it hangs there's no error message, just nothing happens. 

    The manual pasting thing obviously works only if it hangs.

    0 comments No comments