Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

Name of Current Bookmark then create ref field of same name

 
Post new topic   Reply to topic    Computer Forum Forum Index -> word vba customization
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Aug 08, 2007 11:12 am    Post subject: Name of Current Bookmark then create ref field of same name Reply with quote

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.

Quote:
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.
Back to top
Google
Sponsor





PostPosted: Wed Aug 08, 2007 11:12 am    Post subject: Advertisement

Back to top
Guest






PostPosted: Wed Aug 08, 2007 11:52 am    Post subject: Re: Name of Current Bookmark then create ref field of same n Reply with quote

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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> word vba customization All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum