Consulting

Results 1 to 6 of 6

Thread: Loop through shapes on current page

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Dec 2015
    Posts
    9
    Location

    Loop through shapes on current page

    Is there a way to loop through the shapes on only the current page of a Word document? I can get the current page number, and I know how to loop through all pages and shapes in the document. But I only want to work with a single page in the middle of the document. Probably I'll have to loop through all shapes and ask each shape what page it is on. Maybe an algorithm like this would work?

    get and save the current page number
    loop through all shapes in the document
    select each shape in turn (and hope that resets the current page?)
    use selection.Information() to get the current page number of the selected shape
    (or use Shape.Anchor.Information(wdActiveEndPageNumber))
    
    If the page numbers match
      - then this shape is on the original current page

    UPDATE: Yes, this algorithm worked fine. Here's a bit of code:

    curpage = selection.Information(wdActiveEndPageNumber)
    For Each shp In doc.shapes
       shapepage = shp.Anchor.Information(wdActiveEndPageNumber)
       If curpage = shapepage Then
          ' do your thing with the shape on the original current page
       End If
    Next
    Last edited by kkkwj; 07-11-2018 at 07:12 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •