Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
danosoft
Specialist
Specialist

Macro to select a specific Cycle group

i use this expression for select a specific cycle group in a macro

Set group = ActiveDocument.GetGroup("group")

group.Cycle 3

is ok, but i want to select my cycle with name not with the idorder, is possible?

i need that becouse if i select for id, never return the same cycle it depend from what cycle is selected in the moment

thanks

 

1 Solution

Accepted Solutions
danosoft
Specialist
Specialist
Author

Thank you, but i see the fld.name always change the values. By the way i change the solution in this mode:

set group = ActiveDocument.GetGroup("GROUPNAME")
set gp = group.GetProperties

do while activedocument.evaluate("=GetCurrentField([GROUPNAME])") <> "NAME_FIELD"
        group.Cycle 1
loop

 

View solution in original post

8 Replies
marcus_sommer

I think the following features from the APIGuide.qvw will be useful to develop an appropriate matching-logic:

grafik.png

especially those one:

rem show fields of first group in document
groups = ActiveDocument.GetGroups
set gp = groups(0).GetProperties
set vars = gp.FieldDefs
for i = 0 to vars.Count-1
set fld = vars(i)
msgbox("field " & i+1 & " is " & fld.Name)
next

- Marcus

danosoft
Specialist
Specialist
Author

Thanks you but it is not a solution, not resolve

marcus_sommer

You need to build the solution yourself. With the above mentioned loop it's possible to read either the index and the name of the group-fields - means picking the wanted name from there returns the index and this could be used to switch between the cyclic-fields again. Just try not directly to toggle between the fields else use msgbox to return the names and indexes to see that your logic worked and apply it then to your final macro.

- Marcus

danosoft
Specialist
Specialist
Author

No sorry those is not the solution, becouse if i wrote:

set vars = gp.FieldDefs
for i = 0 to vars.Count-1
set fld = vars(i)
if fld.Name="GROUPELEMENT" then
msgbox("field " & i+1 & " is " & fld.Name)
group.Cycle i+1
end if
next

it not work, becouse the group.Cycle <number> is not the ID of the group element so if i put number 5 for example in group.Cycle, i will have not GROUPELEMENT but always different group element

 

marcus_sommer

Yes, just looked in the APIGuide and it's not the group-index else the number of cycling-steps:

grafik.png

- Marcus

danosoft
Specialist
Specialist
Author

Yes as i said.... so how can i solve the problem?

marcus_sommer

I think the difference between the index of the active field and your wanted field should deliver the number of cyclic-steps. The above mentioned loop returned the (static) index and there you could pick the index from your wanted field and with:

groups=ActiveDocument.GetGroups
set fld = groups(0).GetActiveField

you get the active field and you could again pick this index-value - and the difference should be your value (you may also consider a possible forward- and a backward-logic - means the calculation might be different if the index from the wanted field is higher or lower as from the active field).

- Marcus

danosoft
Specialist
Specialist
Author

Thank you, but i see the fld.name always change the values. By the way i change the solution in this mode:

set group = ActiveDocument.GetGroup("GROUPNAME")
set gp = group.GetProperties

do while activedocument.evaluate("=GetCurrentField([GROUPNAME])") <> "NAME_FIELD"
        group.Cycle 1
loop