Consulting

Results 1 to 3 of 3

Thread: Forcing cross-references to ignore bookmark names

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    To ensure that only generic references are used, we can leverage the fact that bookmarks have a specific structure. By checking if the heading's name starts with "_Ref", we can determine if it's a generic reference.

    VB.Net
    Sub InsertCrossReferences()
        Dim Heading As Heading
        
        For Each Heading In ActiveDocument.Headings
            Selection.InsertCrossReference ReferenceType:="Heading", _
                ReferenceKind:=wdNumberNoContext, ReferenceItem:=Heading.Name, _
                InsertAsHyperlink:=True, IncludePosition:=False
            Selection.TypeText Text:=vbTab
            
            ' Check if the heading name is a generic reference
            If Left(Heading.Name, 4) <> "_Ref" Then
                ' If not, use generic reference
                Selection.InsertCrossReference ReferenceType:="Heading", _
                    ReferenceKind:=wdContentText, ReferenceItem:=Heading.Name, _
                    InsertAsHyperlink:=True, IncludePosition:=False
            Else
                ' If it's a generic reference, use the existing cross-reference
                Selection.InsertCrossReference ReferenceType:="Heading", _
                    ReferenceKind:=wdContentText, ReferenceItem:=Heading.Name, _
                    InsertAsHyperlink:=True, IncludePosition:=False
            End If
        Next Heading
    End Sub
    Last edited by georgiboy; 08-20-2024 at 12:28 AM. Reason: Removed spam

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •