kkkwj
07-11-2018, 06:58 PM
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
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