Copy Paste

I often wonder why a code doesn't work. Sometimes, however, an even more interesting question arises: Why does this code work? How is that possible? Usually these quirks of CorelDRAW etc. are described as bugs. Below is an example where it is not clear why a MsgBox included in a For each.....Next loop followed by Sendkeys "{Enter}" only works once. And that now, as I present the question to the esteemed CorelDRAW community, my answer is now clear. If you have similar observations, please share them here.
Thanks to JM1977 for the posted question which gave me a clue as to why his code wasn't working. It was even more unclear to me why my code was working. This is a macro that copies the active shape and then pastes it into every single page of the document. Below is the JM1977 trouble code and my solution, which is not clear why it works this way. As a final result, the task of sticking the active form to each page is accomplished. What is the main takeaway from this case - to avoid Copy / Paste operations in VBA wherever possible. Because otherwise, non-standard solutions will have to be used.
The original question and code of JM1977 can be seen HERE. I think it should be given a lot of attention.

My code is here:
Is used to paste active shape on all pages in document and is assigned to command button on user form

Private Sub CommandButton40_Click()
Dim page1 As Page
Me.Hide
'Sub PasteSelectedShapeOnAllPages()
'Check if there is a selection
If ActiveSelection.Shapes.Count > 0 Then
ActiveSelection.Shapes(1).Copy
ActiveSelection.Delete 'to delete shape on first page, to avoid duplication of shape on first page

' Loop through all pages and paste the shape on each page
For Each page1 In ActiveDocument.Pages

'Two rows below are needed to copy paste active shape on all pages in document
'There is something strange about the code execution of these two lines
'The strange thing is that without the MsgBox ActiveShape only copies the first 5-6 pages.
'Also, it's weird that the MsgBox only shows up once, not as many times as there are pages. Displayed as many times as there are pages if the following line does not exist: SendKeys "'{ENTER}"
'Even weirder is how SendKeys "{ENTER}" manages to hit the OK button on the MsgBox. So it doesn't show up more than 1 time...
MsgBox "NOW I COPY ACTIVE SHAPE TO ALL PAGES OF DOCUMENT" 'paste on each page and if F8 step by step pressed
SendKeys "{ENTER}"

page1.Activate

page1.ActiveLayer.Paste

Next
Else
' Inform the user if there is no selection
MsgBox "Please select a shape to paste.", vbExclamation
End If
SendKeys "+{Backspace}" 'Shift+Backspace assigned to Page Sorter View
End Sub

Any comments and additions on the subject will be gratefully received.
Greetings!

  • without command or keys, can you please give this like this... make a selection and hit the command and luanched, once launched it asks how many duplicate page count required, user enters the copied selection is now pasted on them, if pages existed, then it is okay, if the pages are not existed, then it creates a new pages and pastes