PDA

View Full Version : Userform and bookmark



Augest
10-16-2008, 04:08 PM
Trying to create an utility similar to the Bookmark built in MS Word.

Im trying to count the bookmarks already created within the text.

Then to show them in a textbox within an userform by inputting their index number.

So it would hightlight them within the document, and also have a copy of it in the text box.

Example codes for counting and locating the bookmark using the index (not the bookmark name) would be great.

strbookmark = ActiveDocument.Bookmarks("Bookmark5").Range.Text
TextBox1.Value = strbookmark This code shows the specific bookmark in the textbox but doesn't highlight them in the document

Selection.GoTo What:=wdGoToBookmark, Name:=ActiveDocument.Bookmarks(1).Name This code highlights the bookmark within the document but doesn't show the bookmark in the textbox.

Need a code that does both of these jobs.

There are millions more questions but i would like to solve these ones first.

fumei
10-20-2008, 07:16 AM
"Need a code that does both of these jobs."

Then use both of them.

This seems a little odd to do, and you are going to have some issues. Are you trying to make ALL the bookmarks selected? Say you have five (5) bookmarks in the document, are you trying to have all five actually selected?

That will not be possible.

However, to do what you actually asked for...

Textbox1.Text = ActiveDocument.Bookmarks(1).Range.Text

' notice I used .Text, not .Value

Selection.GoTo What:=wdGoToBookmark, _
Name:=ActiveDocument.Bookmarks(1).Name


Voila. The textbox will show the text from Bookmarks(1), and Bookmarks(1) will be selected.