Macro that will make copies of the selected shape or group on all mages of the document (CorelDraw X6)

Hello, I am trying to write this macro to duplicate or make copies of a selected object on all the pages in the document. (CorelDraw X6)

This seemed simple so I attempted to write it with my limited vba knowledge. For some reason, it is just not working. It only creates the copy on the first page where the object is selected.

The interesting part is that if I run the code step by step (F5) it will do the copies with no problem. But if I play the macro normally it will not. 

The documents I am using have over 100 pages, it is for laser engraving. Also if I create a new document and draw a simple shape and try the macro it will work, but once I open any other file with many shapes on it it will not work. 

Any help here will be appreciated.

Thanks

Jose

Sub PasteSelectedShapeOnAllPages()
'Check if there is a selection
   If ActiveSelection.Shapes.Count > 0 Then
       ActiveSelection.Shapes(1).Copy
       ActiveSelection.Delete

      ' Loop through all pages and paste the shape on each page
      For Each Page In ActiveDocument.Pages
         Page.Activate
         ActiveLayer.Paste
      Next Page
  Else
      ' Inform the user if there is no selection
      "Please select a shape to paste.", vbExclamation
  End If
End Sub

Parents
  • Hello,
    Your code is all right, but not work well
    A little changes make it workable.
    This is CorelDRAW problem, using Copy/Paste

    Sub PasteSelectedShapeOnAllPages()
    Dim page1 As Page

    'Check if there is a selection
    If ActiveSelection.Shapes.Count > 0 Then
    ActiveSelection.Shapes(1).Copy
    'BhBp ActiveSelection.Delete

    ' Loop through all pages and paste the shape on each page
    For Each page1 In ActiveDocument.Pages
    MsgBox "Press OK to continue" 'BhBp this row must exist to work
    SendKeys "{Enter}" 'BhBp this row must exist to work
    'BhBp Page.Activate
    page1.Activate
    page1.ActiveLayer.Paste
    Next page1
    Else
    ' Inform the user if there is no selection
    MsgBox "Please select a shape to paste.", vbExclamation

    End If
    End Sub

    Greetings!

Reply Children
No Data