Apply macro to all pages in Visio 2019

Tan Phat Huynh 41 Reputation points
2020-08-07T01:34:04.303+00:00

Hello, I found a macro below which only works on the active page. I have many pages in my Org Chart; how do I do I apply the macro below to all pages instead of running the macro on each page? Thank you.

Dim shapeLoopIterator As Shape

For Each shapeLoopIterator In Application.ActiveWindow.Page.Shapes ' One way to loop through an object collection
    shapeLoopIterator.CellsSRC(visSectionProp, intPropRow2, visCustPropsValue).FormulaU = """"""
Next
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,255 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Anonymous
    2020-08-10T15:20:42.763+00:00

    @ TanPhatHuynh-4230, you need iterate shapes per each page (not only at active page) like this

    Sub Delete_Belt_Data()
    Dim pg As Page
       Dim shapeLoopIterator As Shape
    For Each pg In ActiveDocument.Pages                                               
         For Each shapeLoopIterator In pg.Shapes ' iterate all pages in active document pages collection !
             shapeLoopIterator.CellsSRC(visSectionProp, intPropRow2, visCustPropsValue).FormulaU = """"""
         Next
    Next
    End Sub
    
    1 person found this answer helpful.
    0 comments No comments

  2. Anonymous
    2020-08-07T05:26:18.487+00:00

    Add these lines for iterate active document pages.

    Dim pg as Page
    For Each pg in Activedocument.Pages
    
    ' put your code there
    
    Next
    
    0 comments No comments

  3. Tan Phat Huynh 41 Reputation points
    2020-08-07T12:45:05.747+00:00

    Thanks Surrogate, when I did that, the changes still only affect the current page, not all pages. Please assist. Thanks.

    New code:

    Sub Delete_Belt_Data()
    Dim pg As Page
    For Each pg In ActiveDocument.Pages

    Dim shapeLoopIterator As Shape
    
    For Each shapeLoopIterator In Application.ActiveWindow.Page.Shapes ' One way to loop through an object collection
        shapeLoopIterator.CellsSRC(visSectionProp, intPropRow2, visCustPropsValue).FormulaU = """"""
    Next                                           
    

    Next
    End Sub

    0 comments No comments