NBSGS123
NBSGS123

Reputation: 3

Inserting/modifying text within cross reference field codes

I've built a custom cross reference tool in Word that allows the user to select multiple consecutive items to cross reference simultaneously. For example, holding down the Shift button and selecting Figure 1 to Figure 5 currently inserts "Figure 1 - 5" in my document, with both numbers being tied to their respective figures as updateable field codes. The field code toggle looks like this:

{ REF _Ref2236712 \h \* \Charformat } - { REF _Ref2236713 \h \# 0}

The field gets inserted into the document through VBA. Here's a sample of how the first field is inserted:

Selection.InsertCrossReference ReferenceType:=ReferenceType.Value, _
referencekind:=wdOnlyLabelAndNumber, referenceitem:=i, insertashyperlink:=HyperlinkChoice

...

Set fld1 = rng1.Fields(1)
fld1.Code.Text = fld1.Code.Text & "\* Charformat "
fld1.Update

How can I modify the field code VBA so that the final result in the document will appear as "Figures 1 - 5" instead of "Figure 1 - 5"? I tried adding strings like 's' and "s" in various places within the brackets but with no success.

Taking it one step further, is it possible to change "Appendix A - Appendix C" to display as "Appendices A - C"? This is a bigger challenge because it doesn't involve simply adding one letter to achieve plurality. Additionally, the numeric formatting switch from earlier (\# 0) doesn't apply to alphabetic characters (meaning Appendix C doesn't get trimmed down to just say C).

Upvotes: 0

Views: 556

Answers (1)

macropod
macropod

Reputation: 13515

You need to modify your macro so it outputs: Figures { REF _Ref2236712 \h # 0} - { REF _Ref2236713 \h # 0}

Upvotes: -1

Related Questions