Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 01-30-2015, 12:06 AM
Guessed's Avatar
Guessed Guessed is offline VBA to Open a Document to a Specific Heading Windows 7 32bit VBA to Open a Document to a Specific Heading Office 2010 32bit
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

This following is a function you could use to go to the right heading. You will need to pass in a string and the function will jump to the first heading that contains that string. The string can also be the heading number. Note I included a sub at the end to show how you might call the function.
Code:
Function GoToMyHeading(str As String)
  Dim doc As Document
  Dim vHeadings As Variant
  Dim v As Variant
  Dim i As Integer
  
  Set doc = ActiveDocument
  vHeadings = doc.GetCrossReferenceItems(wdRefTypeHeading)
  i = 0
  
  For Each v In vHeadings
    i = i + 1
    If InStr(v, str) > 0 Then
      Selection.GoTo What:=wdGoToHeading, Which:=wdGoToAbsolute, Count:=i
      Exit Function
    End If
  Next v
  
  MsgBox "Couldn't find the heading containing: " & str
End Function

Sub GoToMyHeading_Test()
  GoToMyHeading "3.2.1"
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Tags
heading numbering, search, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA to Open a Document to a Specific Heading How to Restore Heading 1, Heading 2, etc. within a Word Document cheech1981 Word 9 01-11-2017 02:14 AM
VBA to Open a Document to a Specific Heading Formula to open external file with specific program (like open with) pemartins Excel 16 02-24-2014 11:39 PM
VBA to Open a Document to a Specific Heading Deleting A blank Line that has a specific heading style , word 2010 & 2013 SteveWcg Word 5 01-08-2014 10:37 PM
VBA to Open a Document to a Specific Heading Macro to replace one specific heading style with another ubns Word VBA 44 09-04-2012 08:17 PM
VBA to Open a Document to a Specific Heading Using Hyperlink to open Word Document at Specific Header rossi45 Word 2 05-04-2012 06:03 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:25 PM.


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