View Single Post
 
Old 12-10-2023, 10:45 AM
nubuki nubuki is offline Windows 10 Office 2021
Novice
 
Join Date: Dec 2023
Posts: 3
nubuki is on a distinguished road
Default Loop through pages from cursor position to end of pages

I'm trying to create a vba to loop through current page to the end of page and paste a copied shape on each of said pages.
I tried:

Code:
Sub PasteAndAlignItems()

    Dim totalPages As Integer

    Dim currentPage As Integer

    Dim startPosition As Range

    totalPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

    Set startPosition = Selection.Range

    For currentPage = 1 To totalPages

        startPosition.Select

        Selection.PasteSpecial Placement:=wdInLine

        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1

    Next currentPage

End Sub
Works for text but not shapes; shapes get pasted on the same page with the cursor
Anyone knows what's wrong?
It would be very helpful if someone could add a snippet to position the pasted shape with horizontal alignment (left relative to page), vertical alignment (top relative to page).

Last edited by nubuki; 12-10-2023 at 10:47 AM. Reason: Grammatical fixes
Reply With Quote