Hi Steve,
It seems this only works if 'show hidden bookmarks' is 'on'. try the following:
Sub CrossRefThisListPara()
Application.ScreenUpdating = False
Dim i As Integer, xRefs As Variant, rngTmp As Range, blnStatus
blnStatus = ActiveDocument.Bookmarks.ShowHidden
ActiveDocument.Bookmarks.ShowHidden = True
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 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
ActiveDocument.Bookmarks.ShowHidden = blnStatus
Application.ScreenUpdating = True
End Sub
One quirk I've just noticed is that the code still won't assign a bookmark name for the very last list paragraph in the document - if that's the last paragraph in the document. Haven't figured that one out yet, but it's easy enough to simply scroll through
the Insert|Cross-Reference dialogue to the last entry to create that one. Thereafter the code inserts the xref for that para also.
Cheers,
macropod MS MVP - Word