我已经根据我的需要调整了这个其他答案。我的更改查看填充的数组并将所选文本与标题文本而不是标题编号进行匹配,以及其他一些小的更改。
Sub InsertCrossRef()
'thank you stackoverflow:
/sf/ask/3329152151/
reference-based-on-selection
Dim RefList As Variant 'list of all available headings and
numbered items available
Dim LookUp As String 'string to be lookedup
Dim Ref As String 'reference string in which there is to be searched
Dim s As Integer, t As Integer 'calculated variabels for the string changes
Dim i As Integer 'looping integer
On Error GoTo ErrExit
With Selection.Range
' discard leading blank spaces
Do While (Asc(.Text) = 32) And …Run Code Online (Sandbox Code Playgroud)