Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-28-2016, 12:30 PM
jroger05 jroger05 is offline How to add a bookmark to text within a header Windows XP How to add a bookmark to text within a header Office 2003
Novice
How to add a bookmark to text within a header
 
Join Date: Aug 2010
Posts: 6
jroger05 is on a distinguished road
Default How to add a bookmark to text within a header

How to add a bookmark to text within a header

I am a novice to VBA, and have gathered some VBA from the web to suit my needs. However I am trying to add a bookmark to text within a heading.

The heading is of the format:
1.1.1.1.1 Register Name Verbose | register_name | register address.

I have used the following code to find all the headings of level 5, extracted the register name from the heading and put it into a variable to be used for the bookmark name, however I am unable to add the bookmark.
I am getting an error when I try to add the bookmark saying it requires an object. I thought I was providing the object with the bookmark part, but not sure what to do.

Thanks for any help,
Jim
----------------------------------------------------------------------------
Sub Traverse_Headings()
'Define the variables
Dim heading As Range
Dim myHeadings As Variant
Dim first_bar


Dim sec_bar

Set heading = ActiveDocument.Range(Start:=0, End:=0)
myHeadings = ActiveDocument.GetCrossReferenceItems(wdRefTypeHea ding)
For icount = LBound(myHeadings) To UBound(myHeadings)
' Subtract
Level = GetLevel(CStr(myHeadings(icount)))

If Level = 5 Then
' Find the position of the bars in the heading. The text in the middle is
' what we are looking for. So find the first bar, find the second bar, and then use the mid function to find the middle
first_bar = InStr(1, myHeadings(icount), "|", 1)
sec_bar = InStrRev(myHeadings(icount), "|")
reg_name = Mid(myHeadings(icount), first_bar + 2, sec_bar - first_bar - 2)
bkmark_name = "C3_" & reg_name & "_desc"

'Once we find that there is a register name need to create the bookmark based on the positions found above.
With ActiveDocument.Bookmarks
.Add Range:=myHeadings(icount).Range, Name:=bkmark_name
.DefaultSorting = wdSortByName
.ShowHidden = False
End With

End If

Next icount
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Bookmark, move to bookmark, execute code, repeat raymm3852 Word VBA 10 04-15-2016 06:21 PM
Add a bookmark to the Header using Word VBA ChrisDevrell Word VBA 2 02-06-2015 04:15 PM
Adding field in word in header in a bookmark in table with Excel vba Late Binding Hdr Excel Programming 6 02-11-2013 02:58 AM
How to add a bookmark to text within a header Open header to insert text into bookmark Amapola188 Word VBA 3 07-12-2012 05:16 PM
How to add a bookmark to text within a header Word 2003 - IncludeText Does Not Include Bookmark Text if in a Form Text Control skarden Word 1 12-12-2011 10:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:42 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