Re: one column listbox, multiple bookmarks, spread*** link

From: LizPCS (LizPCS.11wv2m_at_nospam.WordForums.com)
Date: 02/19/04


Date: Thu, 19 Feb 2004 14:43:39 -0600


Ok, I am so close to getting this...I mean sooooooooo close. All I need
it to do at this point is say "if the user selects something in the
listbox then" blah blah blah. I have the "blah blah" I just don't know
how to use an if statement with a listbox. Any idea? I will keep
trying. BTW here is how I got everything else I was questioning in my
previous post -

I got rid of the DAO stuff in UserForm_Initialize() and used code care
of Doug Robbins from a previous post of mine in VBA beginners

Private Sub UserForm_Initialize()
Dim sourcedoc As Document, i As Integer, j As Integer, myitem As Range,
m As Long, n As Long
Application.ScreenUpdating = False
' Open the file containing the table
Set sourcedoc = Documents.Open(FileName:="C:\WordTP\Authors.doc")
' Get the number of rows in the table less one
i = sourcedoc.Tables(1).Rows.Count - 1
' Get the number of columns in the table
j = sourcedoc.Tables(1).Columns.Count
' Set the number of columns in the Listbox to match
' the number of columns in the table of client details
ListBox1.ColumnCount = j
' Define an array to be loaded with the client data
Dim MyArray() As Variant
'Load client data into MyArray
ReDim MyArray(i, j)
For n = 0 To j - 1
For m = 0 To i - 1
Set myitem = sourcedoc.Tables(1).Cell(m + 2, n + 1).Range
myitem.End = myitem.End - 1
MyArray(m, n) = myitem.Text
Next m
Next n
' Load data into ListBox1
ListBox1.List() = MyArray
' Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

I just inserted my excel file into a word doc called authors.doc. Then
to only show the initials in the list box I made sure initials was the
first column in the table and I did what Doug Robbins suggested on
another post. Make the column widths for the 1st column of the list
box the same size as the column width of initials in authors.doc and
the rest of the columns in the list box = 0 (column width property use
semicolons to separate columns 72; 0; 0; 0).

Then after all my other stuff in CommanButton1_Click I wrote:
With Active Document
If Listbox1.????????????????????????
Bookmarks("lh_name").Range = ListBox1.List(ListBox1.ListIndex,
1)
Bookmarks("member").Range = ListBox1.List(ListBox1.ListIndex,
2)
Bookmarks("email").Range = ListBox1.List(ListBox1.ListIndex,
3)
Bookmarks("aname").Range = ListBox1.List(ListBox1.ListIndex,
1)
Bookmarks("initials").Range =
ListBox1.List(ListBox1.ListIndex, 0)
End If
If chkauthor = True Then
Bookmarks("lh_name").Range = txtAuthor.Text
Bookmarks("aname").Range = txtAuthor.Text
End If
End With

So ListIndex, 0 = the first column of the list box (first column of the
table); listIndex, 1 = the second column and so on. And I made a check
box called chkauthor for the other author problem. Now I just need the
question marks filled in.

I thought I would share my progress as I had to review a number of
different posts and combine answers and code from each to get to this
point. Again, thanks to all who post and provided me with the pieces
for this code and many others. If anyone can help with this final
issue it would be greatly appreciated. The sooner the better.
Thanks.
Liz

------------------------------------------------
~~ Message posted from http://www.WordForums.com/


Loading