> Hi Michael,
>
> 1. I don't know what would have caused two copies of the bookmark names to
> appear in the list -- I'd have to see the code of the userform as it was
> when that happened.
>
> 2. Yes, ListBox1.List is a special name for the collection of items shown in
> the box. There are two ways to put items into the list: either add them
> one-by-one with the AddItem method (my code) or assign an array to the .List
> property (your code). You wouldn't use both methods in the same code. (Maybe
> that's how you got two copies?) If you want only selected bookmark names in
> the list, the array method is easier to program.
>
> 3. Each of the subroutines in the userform is what's known as an "event
> handler"; that is, when something happens, VBA automatically calls the code
> that handles that something (event). The name of the subroutine tells you
> which event it handles. The Userform_Initialize event handler gets called
> when the userform is starting up but hasn't been displayed yet. That's the
> time to load the list into the list box.
>
> The ListBox1_Click event handler gets called when the user clicks somewhere
> inside the list box, but you want the list to be in place already before
> that could happen. You might use that click event to load data into another
> box in the userform, or to enable/disable a command button, or something
> else like that.
>
> 4. Analyze the statement
>
> ActiveDocument.Bookmarks(ListBox1.List(ListBox1.ListIndex)).Select
>
> starting with the innermost pair of parentheses. The property
> ListBox1.ListIndex is the number of the currently selected item in the list,
> starting with 0 at the top of the list and increasing as you go downward.
> Taking your example's array of items, let's say the user clicked on the
> bookmark name "chapter2" and then clicked the OK button. At that point,
> ListBox1.ListIndex is equal to 1.
>
> The expression ListBox1.List(ListBox1.ListIndex) means "find the entry in
> the list whose number is ListBox1.ListIndex, and return the string value you
> find there". In the example, when ListBox1.ListIndex is equal to 1, that
> value is the string "chapter2".
>
> Now that string is used to look in the collection ActiveDocument.Bookmarks,
> find the bookmark whose name is "chapter2", and select it.
>
> 5. Yes, in a userform the term Me refers to the current userform. That's
> especially useful if you're in the business of writing generic userforms
> that can be called for various purposes from various other places. It's good
> practice to use "Me" instead of the UserForm1 name, because the current
> userform may not be named UserForm1 at run time.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ:
http://word.mvps.org> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
>
> Michael F wrote:
> > Jay,
> >
> > I finally got it working so thank you for the code that got me to this
> > point. I would like to get some other questions cleared up if you
> > don't mind. Below are the contents of my userform as it now stands.
> >
> > For the UserForm_Initialize macro, I tried your code (For Each
> > bkmk...) and it presented two sets of all the user defined bookmarks
> > and did not go to the selected bookmark. I replaced it with the
> > ListBox1.List array that I found elsewhere in this forum and that
> > worked after I added your code to command button. I wanted to
> > present only selected bookmarks in the listbox so as to limit the
> > choices.
> >
> > Is Listbox.List a special name for a variable or could it be called
> > antything else?
> >
> > I was wondering why do I need a UserForm_Initialize macro? When I
> > created the listbox, the macro for it was named ListBox1_Click. I
> > thought that was where you placed the code for the listbox, but it
> > didn't work when I put the array in that macro. What would you
> > usually place in ListBox1_Click?
> >
> > For the command button, could you write a sentence that states what
> > the statement is saying beyond "select a bookmark in the active
> > document..."
> >
> > Finally, is "me.hide" explained in the online help anywhere? I take
> > it that "me" is some shorthand for the current userform.
> >
> > Yours,
> >
> > Michael F
> > ------------------------------------
> >
> > Private Sub CommandButton1_Click()
> > ActiveDocument.Bookmarks(ListBox1.List(ListBox1.ListIndex)).Select
> > Me.Hide
> >
> > 'ActiveDocument.Bookmarks(ListBox1.List).Select
> > 'UserForm1.Hide
> >
> > End Sub
> >
> > Private Sub Label1_Click()
> > 'label for the userform
> > End Sub
> >
> > Private Sub ListBox1_Click()
> >
> > End Sub
> >
> > Private Sub UserForm_Initialize()
> >
> > ListBox1.List = Array("chapter1", "chapter2", "chapter3", "chapter4",
> > _ "chapter5", "chapter6", "chapter7", "chapter8", "chapter9",
> > "chapter10", _ "appendixA", "appendixB")
> >
> > ' Dim bkmk As Bookmark
> > ' For Each bkmk In ActiveDocument.Bookmarks
> > ' ListBox1.AddItem bkmk.Name
> > ' Next
> > ' ListBox1.ListIndex = 0
> >
> > End Sub
> >
> > Private Sub UserForm_Click()
> >
> > End Sub
> > ---------------------------------------------------------------
> >
> > "Jay Freedman" wrote:
> >
> >> To load the listbox with the names of the bookmarks in the document,
> >> use code in the userform like this:
> >>
> >> Private Sub UserForm_Initialize()
> >> Dim bkmk As Bookmark
> >> For Each bkmk In ActiveDocument.Bookmarks
> >> ListBox1.AddItem bkmk.Name
> >> Next
> >> ListBox1.ListIndex = 0
> >> End Sub
> >>
> >> For the command button, use something like this:
> >>
> >> Private Sub CommandButton1_Click()
> >> ActiveDocument.Bookmarks(ListBox1.List(ListBox1.ListIndex)).Select
> >> Me.Hide
> >> End Sub
> >>
> >> That assumes that the macro in the regular module that launches the
> >> userform looks something like this:
> >>
> >> Sub DisplayUserForm()
> >> Dim uf As UserForm1
> >> Set uf = New UserForm1
> >> uf.Show
> >> Set uf = Nothing
> >> End Sub
> >>
> >> --
> >> Regards,
> >> Jay Freedman
> >> Microsoft Word MVP FAQ:
http://word.mvps.org> >> Email cannot be acknowledged; please post all follow-ups to the
> >> newsgroup so all may benefit.
> >>
> >> On Tue, 19 Sep 2006 12:49:02 -0700, Michael F
> >> <MichaelF[ at ]discussions.microsoft.com> wrote:
> >>
> >>> Hi,
> >>>
> >>> As a technical writer, I dabble with macros and VBA. I created a
> >>> userform with a textbox in which you can enter a bookmark name (if
> >>> you know what it is) and a command button that selects that
> >>> bookmark.
> >>>
> >>> How do I code a listbox to present a set of choices? I saw the
> >>> following in the forum but there must be more code I'm missing.
> >>>
> >>> ListBox1.List = Array("Apples", "Oranges", "Pears", "Apricots",
> >>> "Plums")
> >>>
> >>> For the command button, is the following sufficient for it to work?
> >>>
> >>> Private Sub CommandButton1_Click()
> >>> ActiveDocument.Bookmarks(ListBox1).Select
> >>> UserForm1.hide
> >>> End Sub
> >>>
> >>> Thank you.
> >>>
> >>> Michael F.
>
>
>