Код Máté Juhász адаптирован для добавления перекрестных ссылок на пронумерованные элементы (номера абзацев).
Ссылку на абзац можно добавить, введя его номер следующим образом:
- 7.8.9 или 7,8,9 или 789 для пункта 7.8.9
- 1 для пункта 1
- 11 для пункта 1.1
- 11. для пункта 11 (если есть также 1.1)
Макрос код:
Sub AddNumberedReferenceDialog()
Dim tit As String
Dim chId As String
Dim refItems As Variant
Dim idx As Integer
Dim refAdded As Boolean
Dim chName As String
tit = "Add cross-reference"
refAdded = False
refItems = ActiveDocument.GetCrossReferenceItems(wdRefTypeNumberedItem)
chId = ""
Do
chId = InputBox("Enter paragraph number in a.b.c form (use . or , as a separator or no separator 'abc'; if you need to search '11' instead '1.1' enter '11.')", _
tit, chId)
If chId <> "" Then
chId = Replace(chId, ",", ".")
For idx = LBound(refItems) To UBound(refItems)
chName = Trim(refItems(idx))
If InStr(1, chId, ".") = 0 Then chName = Replace(chName, ".", "")
If InStr(1, chName, chId) = 1 Then
If MsgBox("Paragraph [" & Trim(refItems(idx)) & "] was found. Do you like to insert cross-reference?", vbYesNo, tit) = vbYes Then
Selection.InsertCrossReference referencetype:=wdRefTypeNumberedItem, ReferenceKind:=wdNumberNoContext, ReferenceItem:=idx, _
InsertAsHyperlink:=True, IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
refAdded = True
Else
Exit Sub
End If
Exit For
End If
Next idx
If Not refAdded Then refAdded = MsgBox("Paragraph [" & chId & "] was not found in the document. Do you like to enter another paragraph number?", vbYesNo, tit) = vbNo
Else
Exit Sub
End If
Loop Until refAdded
End Sub