"clipboard in use" when copying/pasting multiple shapes

Started by scott, February 26, 2021, 07:09:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

scott

This is a simplified version of code I'm using to copy then paste a set of shapes to a location on the page -- basically I'm creating a stack of shapes.
Sub TestCopyPaste()

    Dim shp     As Visio.Shape
    Dim sel     As Visio.Selection
   
    Set sel = ActiveWindow.Selection
    For Each shp In sel
        shp.Copy
        ActivePage.PasteToLocation 4.25, 2, 0
    Next shp

End Sub


With three or fewer shapes it runs fine. But with four or more it stops and shows the attached error message at least once. Note that clicking Debug and then F5 does allow the code to run.

I'm assuming this is a timing issue because the code runs fine if you step through it. I've tried Sleep(1000) and DoEvents but neither appeared to have any effect.

Do I need to clear the clipboard before each copy/paste? Is there a ClipboardIsIdle event I can get from Windows?

Thanks