![]() |
|
|
|
#1
|
||||
|
||||
|
The first two problems you have are:
1. wdRefTypeCustomHeading doesn't exist 2. Selection.GoTo doesn't have a type that correlates with wdRefTypeNumberedItem Try this version of what I think you are trying to do. Code:
Sub GoToHeading_test2()
Dim sArticleNum As String
sArticleNum = Trim(LCase(InputBox("Enter the article number", "Enter article number")))
If SetRef(wdRefTypeHeading, sArticleNum) Then Exit Sub
If SetRef(wdRefTypeNumberedItem, sArticleNum) Then Exit Sub
'If you get this far the clause number wasn't found
MsgBox "Couldn't find the heading containing: " & sArticleNum
End Sub
Function SetRef(iType As Integer, sParaNum As String) As Boolean
Dim vArray As Variant, i As Integer, v As String, vLower As String
Dim sCode As String, aXRef As Field, aRng As Range
vArray = ActiveDocument.GetCrossReferenceItems(iType)
For i = LBound(vArray) To UBound(vArray)
vLower = Trim(LCase(vArray(i)))
Debug.Print sParaNum, vLower
If vLower Like sParaNum & "*" Then
Set aRng = ActiveDocument.Range(Start:=0, End:=0)
aRng.InsertCrossReference ReferenceType:=iType, ReferenceKind:=wdContentText, ReferenceItem:=i, InsertAsHyperlink:=True
Set aXRef = ActiveDocument.Fields(1)
Debug.Print aXRef.Code
sCode = Split(Trim(aXRef.Code), " ")(1)
Selection.GoTo What:=wdGoToBookmark, Name:=sCode
aXRef.Delete
SetRef = True
Exit For
End If
Next i
End Function
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
| Tags |
| heading numbering |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using numbered list style, how to indent text immediately following heading to match heading indent? | SpechtacularDave | Word | 3 | 09-25-2019 01:22 PM |
| Capturing Numbered Headings and Sentences within Heading | lvalx | Word VBA | 0 | 05-05-2017 06:32 AM |
| Restarting numbered lists in each Heading section with VBA | CN13579 | Word VBA | 2 | 11-02-2016 11:54 AM |
Modify a numbered heading style
|
TheQueenBea | Word | 3 | 06-05-2012 12:12 PM |
| MS Word 2007 numbered heading problem | gdsmithtx | Word | 0 | 04-29-2009 02:20 PM |