How to display bookmark names within MS Word editor ?

O

Oscar

I am automating Word documents from a VB application by setting the text
values in bookmarks within the Word documents. Anything works well. I only
find it a hassle of work to edit the documents in MS Word when dealing with
bookmarks. I can only see the location of the bookmarks by a 'I' sign and
not the name of the bookmarks. I was wondering whether there is an option to
display these names instead of looking for them by 'goto bookmark' which is
a outdated feature.

In case this is not possible, is there another option for my purpose?

regards,
Oscar
 
L

Lars-Eric Gisslén

Oscar,

You can select Insert in the main menu and Bookmark in the dropdown menu.
The book mark you are on is displayed in the dialog. To make this easier I
have placed the InsertBookmark command on one of the default toolbars. Then
I place the insertion point on the bookmark, klick on the button on the
toolbar and can see the name of the bookmark. Then I just hit the Esc button
to close the dialog.

Regards,
Lars-Eric
 
J

Jay Freedman

Hi, Oscar,

Add this macro to your template:

Public Sub DisplayBookmarkName()
' If selection is in a bookmark, show the name
Dim oBK As Bookmark
Dim BKFound As Boolean
For Each oBK In ActiveDocument.Bookmarks
If Selection.Range.InRange(oBK.Range) Then
BKFound = True
StatusBar = oBK.Name
Exit For
End If
Next oBK
If Not BKFound Then
StatusBar = "Not in a bookmark"
End If
End Sub

Then add menu entries to various right-click ("shortcut") menus to call this
macro (see
http://www.mvps.org/word/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm for
instructions).

When you right-click a place in the document and select the macro's item, it
will show the bookmark's name on the status bar at the bottom of the Word
window.
 
L

Larry

In addition to what Lars-Eric suggested, if you don't want to bring up
the Bookmarks dialog box with all the bookmarks in it, but just want to
see the name of the current bookmark, you could use this macro instead.


If Selection.Bookmarks.Count < 1 Then
MsgBox "No bookmark selected.", vbOKOnly, "Selected Bookmark."
Else
MsgBox "Selected bookmark: " & Format(Selection.Bookmarks(1).Name,
">"), vbOKOnly, _
"Selected Bookmark"
End If

This brings up a simple message book with the name of the selected
bookmark. That might be easier and quicker to read than the Bookmark
dialog.

Larry
 
L

Lars-Eric Gisslén

Larry,

There is a reason why I use my solution. I also have a button that toggles
hiding/displaying bookmarks in the document.
We have developed a number of contracts that will be changed by which
selections are made in a form that is displayed when a contract is created.
There are plenty of bookmarks in the document, even nested bookmarks. When I
put the insertion point in a bookmark I click on the bookmark button in the
toolbar. The bookmark is then automatically selected in the 'Insert
Bookmark' dialog. Then I can click on the 'Goto' button to get the range of
the bookmark selected in the document. Then I will also see if there are
other bookmarks within the selection. I thought this was the simpliest
solution to achieve that and no macros involved. I placed the toolbar
buttons on a toolbar belong to an Add-In template so even if I have to
replace normal.dot my buttons will still be available.

Regards,
Lars-Eric
 
L

Larry

Yes, that's neat the way the dialog box opens with the current bookmark
indicated, and then if you press GoToBookmark, the entire bookmark gets
selected.

Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top