PDA

View Full Version : Forcing cross-references to ignore bookmark names



YossiD
02-04-2024, 05:56 AM
I have these commands in a Word macro (Word 2013):


Selection.InsertCrossReference ReferenceType:="Heading", _
ReferenceKind:=wdNumberNoContext, ReferenceItem:=Step, _
Selection.TypeText Text:=vbTab
Selection.InsertCrossReference ReferenceType:="Heading", _
ReferenceKind:=wdContentText, ReferenceItem:=Step, InsertAsHyperlink:=True _
, IncludePosition:=False InsertAsHyperlink:=True, IncludePosition:=False

For each Heading in a document, these commands print the heading number followed by a tab followed by the heading text. Like this:
‎1 This is a first level heading with bookmark
‎2 This a first level heading without bookmark

Some of the headings are bookmarked, and in those cases the cross-references use the bookmark names rather than generic references. Like this:

{ REF FirstLevelHeadingwBM \n \h } { REF FirstLevelHeadingwBM \h }

For headings that are not bookmarked, the cross-references look like this:

{ REF_Ref157949988 \n \h } { REF _Ref157949988 \h }

Since I might delete some of the bookmarks at a later time, I want the macro to only use the generic Refs and to never use the bookmark names. How can I modify the code to prevent using the bookmark names as Refs in the cross-references?

Also, is there a simple way to get the \* charformat switch incorporated in the cross-references, or would I need to add them using separate statements?