My problem is: After a mail merge any cross referenced items have been stripped to hard text. The document is a legal agreement with cross references to various clauses, sections, etc. I was following another route to insert hyperlinks; however, when the source data file changes, it will change all agreements – not good! So here I am back at mail merge and now needing to write vba so that the user can click on a button to reinsert the cross references after the mail merge… (and I’m quit rusty with vba lately)!!
So far, I have written code to search for any strings that include a space and number (0-9) and replace the space with a non-breaking space. Now my task is to find any keywords with a non-breaking space and number (i.e., article 7 or clause 3.2 or Schedule A) and search through the list of cross references for that number and replace the hard text number with the cross reference. I am using styles Headings 1-9 in the document with attached numbered lists. I have been researching this for a couple of days found different varities of the following code which does not seem to do anything. I’m not even sure this code is pointing in the right direction?
Dim myHeadings
Dim i
Dim strNumberedHeading As String
myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading)
For i = 1 To UBound(myHeadings)
If InStr(LCase$(myHeadings(i)), “article^s”) Then
Selection.InsertCrossReference _
ReferenceType:=wdRefTypeHeading, _
ReferenceKind:=wdPageNumber, ReferenceItem:=i
Selection.InsertParagraphAfter
End If
Next i
Any help would be muchly appreciated… thanx… trish