3 Replies Latest reply: Oct 29, 2015 8:54 AM by Günther Frahm RSS

    Macro: Loop over all groups?

      Does anyone of you know how to loop over all groups using a macro?

      Normally I would count the items in the array I've got through "getgroups" and do a "for...next...loop" over them, but somehow I can't figure out how to count the existing groups (cyclic and drilldown) in the document.The normal count-method doesn't seem to work here.

      Thanks for your help in advance...

        • Macro: Loop over all groups?


          a bit strange, also ubound/lbound do not work. maybe better solutions exist than this one


          sub groupmembers()
          for i = 0 to 5
          on error resume next
          set gp=grouparray(i).GetProperties
          if err <> 0 then
          msgbox("err " & i)
          exit for
          end if
          end sub



          • Re: Macro: Loop over all groups?
            ioannis giakoumakis

            you could use a while not isnull statement instead of for...next

            • Re: Macro: Loop over all groups?
              Günther Frahm

              try this one:

              -> gives you groups and containing fields


              Sub Get_Groups()

                  groups = ActiveDocument.GetGroups


                  For each item in groups

                      set gp = groups(j).GetProperties

                      set gd = groups(j).GetDescription

                      set vars = gp.FieldDefs

                      for i = 0 to vars.Count-1

                          set fld = vars.Item(i)

                          msgbox("Group: " & gd.Name & " - field " & i+1 & " is " & fld.Name)




              End Sub