A family of Microsoft word processing software products for creating web, email, and print documents.
Hi macropod,
Just the 2nd instance or both?
Currently I've just done the 2nd instance:
Sub Add_crossRef_to_selected_para()
Application.ScreenUpdating = False
Dim i As Integer, xRefs As Variant, rngTmp As Range
xRefs = ActiveDocument.GetCrossReferenceItems(wdRefTypeNumberedItem)
With Selection
.Collapse wdCollapseEnd
If .Paragraphs.First.Range.BookmarkID = 0 Then
On Error Resume Next
For i = 1 To UBound(xRefs)
'Ensure each list para has a Bookmark ID allocated by Word
If ActiveDocument.ListParagraphs(i).Range.BookmarkID = 0 Then
Set rngTmp = ActiveDocument.ListParagraphs(i).Range
With rngTmp
.End = .Start
'Create the ID by inserting a Cross-Reference to the current paragraph
.InsertCrossReference ReferenceType:=wdRefTypeNumberedItem, _
ReferenceKind:=wdNumberFullContext, ReferenceItem:=i
'Delete the Cross-Reference
.MoveEnd wdCharacter, 1
.Fields(1).Delete
End With
End If
Next
End If
'Inserting a Cross-Reference to the the selected paragraph, using the Bookmark ID allocated by Word
.InsertCrossReference ReferenceType:=wdRefTypeBookmark, ReferenceKind:=wdNumberFullContext, _
ReferenceItem:=ActiveDocument.Bookmarks.Item(.Paragraphs.First.Range.BookmarkID - 1).Name, _
InsertAsHyperlink:=True, IncludePosition:=False
End With
Set rngTmp = Nothing
Application.ScreenUpdating = True
End Sub
With the above, I either get no xref or a runtime error 5941 (The requested number of the collection does not exist).
Cheers
...Steve