简体   繁体   English

在交叉引用域代码中插入/修改文本

[英]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.我在 Word 中构建了一个自定义交叉引用工具,允许用户同时选择多个连续项目进行交叉引用。 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.例如,按住 Shift 按钮并选择图 1 到图 5 当前会在我的文档中插入“图 1 - 5”,这两个数字都作为可更新的域代码与各自的数字相关联。 The field code toggle looks like this:域代码切换如下所示:

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

The field gets inserted into the document through VBA.该字段通过 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"?如何修改域代码 VBA,使文档中的最终结果显示为“图 1 - 5”而不是“图 1 - 5”? I tried adding strings like 's' and "s" in various places within the brackets but with no success.我尝试在方括号内的不同位置添加像“s”和“s”这样的字符串,但没有成功。

Taking it one step further, is it possible to change "Appendix A - Appendix C" to display as "Appendices A - C"?更进一步,是否可以将“附录 A - 附录 C”更改为“附录 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).此外,之前的数字格式转换 (\\# 0) 不适用于字母字符(意味着附录 C 不会被缩减为仅说 C)。

您需要修改宏,使其输出: Figures { REF _Ref2236712 \\h # 0} - { REF _Ref2236713 \\h # 0}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM