The actual code you need depends critically on a number of details of the way
your document is structured, so the sample below probably won't do what you
need. If you can email an extract from the document, showing some of the
headings and some of the cross-reference locations for them, I'll try to write
some sample code tailored to it. My address is in my profile (click my name
above), or on the contacts page at
http://jay-freedman.info.
Are the headings auto-numbered, rather than manually numbered? If they're
autonumbered, the document has a ListParagraphs collection that contains all the
autonumbered paragraphs. The text to search for can then be extracted from the
members of the collection. If they aren't autonumbered, then the loop will have
to search first for all the headings of the first style, and for each one search
for other occurrences of that text; then repeat for the next style, and so on.
Here's a sample of code that could work if the headings are autonumbered:
Sub demo()
Dim numpar As Paragraph
Dim i As Long
Dim srchStr As String
Dim srchRg As Range
For i = 1 To ActiveDocument.ListParagraphs.Count
Set numpar = ActiveDocument.ListParagraphs(i)
srchStr = numpar.Range.ListFormat.ListString & _
" " & numpar.Range.Text
Set srchRg = ActiveDocument.Range
With srchRg
.Find.Text = srchStr
While .Find.Execute
.MoveEnd wdCharacter, -1
.InsertCrossReference _
ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdNumberFullContext, _
ReferenceItem:=i, _
InsertAsHyperlink:=True
.MoveUntil vbCr
.Text = ". "
.MoveUntil vbCr
.InsertCrossReference _
ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdContentText, _
ReferenceItem:=i, _
InsertAsHyperlink:=True
.MoveUntil vbCr
Wend
End With
Next i
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.