Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 01-12-2023, 10:32 PM
Guessed's Avatar
Guessed Guessed is offline Jump to a numbered item with default heading and custom heading Windows 10 Jump to a numbered item with default heading and custom heading Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
 

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
Jump to a numbered item with default heading and custom heading 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft