I have a macro that allows me to select whatever dimension from a cyclic dimension for a chart and this works really well, I am now looking at doing the same for a cyclic expression but I'm not really sure where to start.
My Macro for the dimension is:
SET grp1 = ActiveDocument.GetGroup("StdListA")
WHILE grp1.GetActiveField.Name <> "DealAggName" DO
If anybody has any clues as to how I can do this I'd appreciate it.
This may help - code to cycle through the expressions for a chart
set chart = ActiveDocument.GetSheetObject("CH01") set cp = chart.GetProperties
' Get a count of the current expressions iCount = cp.Expressions.Item(0).Count
' N.B. Item(0) in this case is the first Expression group - there may be more than one
' Add a new Expression cp.Expressions.Item(0).Add() ' Copy from the first one cp.Expressions.Item(0).Item(iCount).CopyFrom(cp.Expressions.Item(0).Item(0)) 'TempExpr.CopyFrom(cp.Expressions.Item(0).Item(0)) ' Loop Through and Copy from next one for i = 0 to iCount-1
i implemented Nigels approach to set a cycle group by macro code. But his method steps thru all the cycle group elements causing all sheet objects to render over and over again until the right item is finally reached. This is not desirable so after some hefty elaboration with different API features i finally got a working solution. The macro needs two variables to be set. vMacroParam1 expects name of cycle group as string, vMacroParam2 expects name of group member to be selected. I have created a button with 3 Actions (set vMacroParam1 , set vMacroParam2 , trigger SetDimGroupSel) which works as expected.
Sub SetDimGroupSel ' fetch name of group to be selected ------------------ Dim strGrp strGrp = ActiveDocument.Variables("vMacroParam1").GetContent().String
' set instance pointers set grp = ActiveDocument.GetGroup(strGrp) 'returns pointer to Group instance set grpProps = grp.GetProperties ' returns pointer to IGroupProperties instance set fldDefs = grpProps.FieldDefs ' returns pointer to IArrayOfFieldDevEx instance 'set fldItem0 = fldDefs.Item(0) ' returns pointer to IFieldDevEx instance 'msgbox("Item0.Name = " & fldItem0.Name)
' fetch name of currently selected field Dim strActiveField strActiveField = grp.GetActiveField.Name
' fetch name of field to be selecetd ------------------ Dim strNewField strNewField = ActiveDocument.Variables("vMacroParam2").GetContent().String