Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2007

Tip: Looking for answers? Try searching our database.

Name of Current Bookmark then create ref field of same name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
david.inglis@semplefraser.co.uk - 08 Aug 2007 12:12 GMT
I have a large number of word docs with quite a few bookmarks in each,
which are used in a document automation system.

I need to print these documents out with a visible marker of where
each bookmark is and what it's called.

>From reading on here, the only way I can see of doing this is to
create a REF field, which is then related to the relevant bookmark.
This then shows up in printing, with the bookmark name, in the same
location as the bookmark, which is what I want.

However, doing this process manually in each document is a bit of a
pain, because I need to get the name of the bookmark first, then
create the field.

Is it possible to write some VB, macro or whatever, to get the name of
the current bookmark (ie where the cursor currently is - Word knows
the bookmark name the cursor is on, so I'm sure we could get it too),
then create a ref field based on that name?

I'm aware I'll still need to walk through each bookmark, but one click
instead of 4 or 5 will save me a lot of time.

ANy help would be greatly appreciated.
david.inglis@semplefraser.co.uk - 08 Aug 2007 12:52 GMT
After posting I found a bit of code which I've modified, which then
works it's way through all bookmarks and creates the ref field. Here
is the code, in case anyone needs the same thing:

Dim r As Range
Dim b As Bookmark
Selection.Collapse Direction:=wdCollapseEnd
Set r = ActiveDocument.Range(Start:=Selection.Start, _
End:=ActiveDocument.Content.End)
Dim count As Integer
count = 0

With r
   If .Bookmarks.count > 0 Then
   count = .Bookmarks.count
   For x = 1 To count
       Set b = .Bookmarks(x)
       'Now do what you want with the bookmark.
       'For example, select it:
       b.Select
       Selection.Fields.Add Range:=Selection.Range,
Type:=wdFieldEmpty, Text:= _
       "REF " + b.Name, PreserveFormatting:=False
       Next
   Else
       MsgBox "There are no more bookmarks " & _
       "in the document"
   End If
 End With
End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.