Finding a bookmark with a macro

E

EEvans

I need to find a way to locate a bookmark's index number via a macro.
Currently I use, Dialogs(wdDialogInsertBookmark).Show to allow the user to
select the desired bookmark, then they have to click the Goto button. I can
then get the index. The problem is with
Dialogs(wdDialogInsertBookmark).Show, I can not disable the Delete button, if
the user clicks Delete rather than Goto the macro errors out.
Is there a way to display a dialog box, or something else, that will allow
the user to select a bookmark from a list, and then I be able to read the
index for that bookmark?
 
G

Greg

You could create a user form with a ListBox to list the bookmarks and a
command button.

Code something like this should do:

Private Sub CommandButton1_Click()
Dim pName As String
pName = Me.ListBox1.Text
MsgBox ActiveDocument.Bookmarks(pName).Range.BookmarkID
End Sub
Private Sub UserForm_Initialize()
Dim oBkm As Bookmark
For Each oBkm In ActiveDocument.Bookmarks
Me.ListBox1.AddItem oBkm.Name
Next
End Sub
 
E

EEvans

I had thought about something like that, but I don't want to create another
user form. This program is for mutiple users and some would have problems
with adding the form to thier documents. Is there a way to add the form
automatically? If not, is ther another way to list all of the bookmarks so
that the user can select one from the list?
 
R

Russ

I had thought about something like that, but I don't want to create another
user form. This program is for mutiple users and some would have problems
with adding the form to thier documents. Is there a way to add the form
automatically?

The normal.dot is left as pristine as possible for the user to adjust.

The way you add a form automatically is make it part of another global
template or add-in which means the other template is placed in the Microsoft
Office 'Startup' folder (locate by opening MacWord Preferences or WinWord
Tool:Options, tab: File Locations). Then any vba code and 'extra' forms,
menus, toolbars, etc. are automatically available to the user when Word is
started. The user won't be able to alter the global template parts unless he
finds and opens the global template in Word as a document or uses the
'Organizer' to move parts of the global template into his normal.dot
template.
The add-ins are also added by the menu Tools:Templates and Add-Ins... and
can be temporarily disabled anytime by unchecking them via that same menu
choice dialog that appears.
 

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