Pick list of bookmark names? How 2?

T

Tsu Dho Nimh

I want to be able to let the writers insert "boilerplate" from an
document that has one or more bookmarks. They want to be able to mar
their own documents instead of having to make a special "boilerplat
file" for each chunk of text they use. Making several bookmarks in
long document seems more useful to them, and makes cannibalizing ol
documents easier.

(Yes, AutoText could be used, but a busy admin doesn't want to have t
maintain the AutoTexts, and they are having trouble keeping in syn
with each other. Bookmarks are available to anyone who has access t
the file and can be left in the document when obsolete.)

Ideally, they would browse to a file, select it, and have a display o
the available bookmarks appear for them to choose from. Highlighting
bookmark and clicking INSERT would do the usual thing and insert tha
text from the bookmarked file.

I have already written a macro that grabs two hardcoded bookmarks an
sticks the marked text at designated spots in a file ... I'm a bi
baffled by how to make the listing show up and pass the value to th
rest of the macro
 
P

Peter Hewett

Hi Tsu Dho Nimh

You need to iterate (loop through) the bookmarks collection and add the
bookmarks to your ListBox or ComboBox. Add something like this to the
UserForm_Initialize event handler.

' Add all bookmark names to the ListBox
Dim bmItem As Word.Bookmark
For Each bmItem In ActiveDocument.Bookmarks
lstBookmarks.AddItem bmItem.Name
Next

Add this code to the ListBox/ComboBox change event handler:

Private Sub lstBookmarks_Change()

' Select the text marked by the bookmark selected by the user
If lstBookmarks.ListIndex > 0 Then
ActiveDocument.Bookmarks(lstBookmarks.Value).Select
End If
End Sub

This allows the user to see the actual bookmarked text to confirm that
they've selected the correct entry.

You can then copy/paste (whatever mechanism you favour) the text from the
source document to your target document.

HTH + Cheers - Peter
 

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