Retrieving bookmarked content

J

Jason Logue

Hi, I am working on a userform that allows the user to
click a button and load a listbox with bookmarks in a
specific document. The user can then click on one and
click the Command button for the window and it will load
that bookmark name in the specified area of the Word
document/template. I would like the bookmark names to be
available for the user, but I want the content of the
bookmark to be loaded into the template, not the bookmark
name.

Here is the code I have right now:

Sub CommandButton1_Click()


Dim i As Integer, source As Document
Set source = Documents.Open("C:\Documents and
Settings\Logue\My Documents\Allied
Title\exceptions\chapterone.doc")
For i = 1 To source.Bookmarks.Count
ListBox1.AddItem source.Bookmarks(i).Name


Next i


Documents("Chapterone.doc").Close



End Sub


The following code is for the actual userform the listbox
is on:
Private Sub CommandButton2_Click()

With ActiveDocument


.Bookmarks("exceptions1").Range.InsertBefore ListBox1

End With

UserForm3.Hide

End Sub


Thanks for any help!

-Jason
 
J

Jason

Thanks, Jonathan. This is pretty close to what I want.
The client typically selects this information using a
number, and in this case the bookmark name represents the
information. Since I can't put decimal points in numbers
for bookmarks (darn it all), I am typing in things like
oneone, onetwo, onethree, for the bookmark names. I would
like these numbers to be visually available to the client
in the userform, however, I want the bookmarked text to be
the text that is inserted in the document.

Does that make sense?

For example, a client will select Oneone which represents
a paragraph of text. When the client clicks OK on the
userform this text is inserted in the appropriate in the
text.

Thanks again.

-Jason
 
J

Jonathan West

Hi Jason

In that case, what you need is some kind of coding scheme for the bookmark
names. A bookmark name must start with a letter (or an underscore if it is a
hidden bookmark), and can only contain letters, numbers or underscores.

Therefore, it should be fairly straightforward to have the bookmark name in
the form b1_3_2, which you then read, strip off the leadeing letter, replace
the underscores with periods, and post into the listbox as 1.3.2. You do the
reverse process when the user selects the bookmark wheere new text is to be
entered.

Best would be to write a couple of functions to do the conversion back and
forth, and then just apply them to the bookmark name as necessary
 
J

Jason

Thanks, Jonathan.

I think I need to explain this whole process a little more
thoroughly. The user is using a template that generates
four different userforms. On the third userform they need
to be able to select what they call Exceptions, which come
from an Exceptions manual. This Exceptions manual is
large and contains 30+ chapters with around 6-15
exceptions. These exceptions are usually 4 sentences
long. Right now the system for pulling the text up in the
listbox seems to be working fine, but, they are very used
to selecting just the numbers and that's the easiest for
them (for example, 1.1 = It appears from the public record
that there is no means of access to the land. This
Company does not insure against any loss or damage by
reason of lack of access to and from the land.). I would
like them to be able to type in the number 1.1 and have
that pull up the bookmarked text for that number.

My idea now is to create a button on the third Userform
that allows them to access a list of chapters on a
separate window. If they click on the chapter, they will
then get another window with command buttons that are
numbered according to that exceptions. If they click on
the button, they get that exception entered into that
portion of the document. My only problem with this is the
amount of windows, but it helps me get around the number
selection dilemna. If you can think of anything else to
add to this, let me know.

TIA,
Jason
 

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