Link to home
Start Free TrialLog in
Avatar of marrick13
marrick13

asked on

Code to loop through a variable and then loop through a document to format cross references whose types match the variable items

I need code that will take user choices (from checkboxes on a userform that correspond to the Reference Type dropdown in the Word cross reference interface function) and apply them so a macro (‘Apply_Cross_Ref_Style’) that is intended to format cross references formats only those checkbox controls whose names include the reference type (control.name.text). The purpose is to segregate the cross references,  so that I can apply formatting to specific cross references while leaving others of the same type alone.

Example: if I want to format only cross refs that point to captions with the labels of “Figure” and “Table” but leave all other cross references alone (such as headings and numbered items), this is the only way I can think of doing so, since they all have the same REF (or wdfieldref) field type,

I have a sub (‘lblApply_Click”) in the attached file that reads the controls and populates a variable (‘Reftype’) with the truncated names of the Reference Type list items (Numbered list, heading, bookmark, etc.). The idea is then for the ‘Apply_Cross_Ref_Style’ sub to format only those cross references of those types. I have the line ‘If Left(oFld.Result.Text, 6) = "Figure" Then…’ there now to test the concept, and it works, but I need to loop through the ‘Reftype’ variable, which carries the cross reference type names that are selected in the user-checked controls to tell the sub which cross references to format. I believe this requires an array but I don’t know how to write it properly.
CrossRef-Format-Test.docm
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.