C
c.dan.sherman
I'm going through many (hundreds if ont thousands) of documents that
have hand numbered paragraphs and cross-references and converting them
to autonumbered paragraphs and references. I wrote a macro to convert
the paragraphs to numbered heading styles, it works great on every
version of word that I've tested it on. I also have a macro to change
a manual cross reference into a REF field (see below) instead of going
through the CrossReference dialog everytime. It works on Word 2000
and 2003, and almost works in 2007. In 2007 it references the wrong
number (2 items back, i.e. 4.3 becomes 4.1).
I used the debugger to step through and found that it finds the
correct reference, but doesn't insert it correctly.
Sub AutoCrossReference()
Dim myHeadings() As String
Dim strTemp As String
Dim l As Long
Dim i As Long
l = Len(Selection.Text)
strTemp = Selection.Text
myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading)
If l > 0 Then
For i = 1 To UBound(myHeadings)
If Left$(LTrim(myHeadings(i)), l) = strTemp Then
Selection.InsertCrossReference _
ReferenceType:="Heading", _
ReferenceKind:=wdNumberNoContext, _
ReferenceItem:=i, _
InsertAsHyperlink:=False, _
IncludePosition:=False
End
End If
Next i
MsgBox ("Could not find target paragraph. Check your references.")
End If
End Sub
have hand numbered paragraphs and cross-references and converting them
to autonumbered paragraphs and references. I wrote a macro to convert
the paragraphs to numbered heading styles, it works great on every
version of word that I've tested it on. I also have a macro to change
a manual cross reference into a REF field (see below) instead of going
through the CrossReference dialog everytime. It works on Word 2000
and 2003, and almost works in 2007. In 2007 it references the wrong
number (2 items back, i.e. 4.3 becomes 4.1).
I used the debugger to step through and found that it finds the
correct reference, but doesn't insert it correctly.
Sub AutoCrossReference()
Dim myHeadings() As String
Dim strTemp As String
Dim l As Long
Dim i As Long
l = Len(Selection.Text)
strTemp = Selection.Text
myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHeading)
If l > 0 Then
For i = 1 To UBound(myHeadings)
If Left$(LTrim(myHeadings(i)), l) = strTemp Then
Selection.InsertCrossReference _
ReferenceType:="Heading", _
ReferenceKind:=wdNumberNoContext, _
ReferenceItem:=i, _
InsertAsHyperlink:=False, _
IncludePosition:=False
End
End If
Next i
MsgBox ("Could not find target paragraph. Check your references.")
End If
End Sub