View Single Post
 
Old 07-19-2022, 05:15 AM
Aussie_Z Aussie_Z is offline Windows 10 Office 2021
Novice
 
Join Date: Jul 2022
Posts: 2
Aussie_Z is on a distinguished road
Default

I'd like to ask a related follow-on question. Is this macro appropriate to be modified, or can someone suggest how I might, 1) using a Word document like this:

1.0 Heading 1
1.1 Heading 2
2.0 Heading 3

2) When selecting a heading cross-reference, output the following cross reference hyperlinks

Section 1.0, Heading 1

OR

3) What I am really trying to do is have the macro ask for a heading number (e.g., 1.0) and have the VBA put, in the current document location, the heading hyperlinks
(e.g., "Section 1.0, Heading 1")


Sub InsertXrefWithPage2()
Dim StrNm As String
Dim Dlg As Dialog

Set Dlg = Dialogs(wdDialogInsertCrossReference)
Dlg.InsertAsHyperLink = 1
Dlg.Display

With Selection

Dim CurrentStyle As Style
Set CurrentStyle = .Style
.Start = .Start - 1

If .Fields.Count = 0 Then Exit Sub

StrNm = "PAGE" & LTrim(.Fields(1).Code.text)
.Collapse wdCollapseEnd
.InsertAfter ", "
.Style = CurrentStyle
.Collapse wdCollapseEnd

Dim addedField As Field
End With

End Sub
Reply With Quote