Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

ListBox in a Word Document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Doctorjones_md - 03 Nov 2006 16:22 GMT
Please excuse this re-posting -- it's from a thread some weeks back which
may have run out of steam:

Doug,

You seemed rather emphatic about this approach -- I'm sure you derrive a
certain amount of pleasure when someone is successful in using your advice
(as would I) :)

When I run the code you suggested, I get a Run Time Error 5941 -- "The
requested member of the collection does not exist." -- I believe it has
something to do with this line in the code:

   ' Modify the path in the following line so that it matches where you _
Saved LineItems.doc
   Application.ScreenUpdating = False

What am I doing wrong here?  I modified the path to my sourcedoc in the next
line:

   ' Open the file containing the client details
   Set sourcedoc = Documents.Open(FileName:="E:\LineItems.doc")

Here's my code for UserForm1 of DougListBoxTest.doc:
=========================
Private Sub CommandButton1_Click()
Dim i As Integer, Product As String
Product = ""
For i = 1 To ListBox1.ColumnCount
   ListBox1.BoundColumn = i
   Product = Product & ListBox1.Value & vbCr
Next i
ActiveDocument.Bookmarks("Product").Range.InsertAfter Product
UserForm1.Hide

End Sub

Private Sub UserForm_Initialize()
Dim sourcedoc As Document, i As Integer, j As Integer, myitem As Range, _
m As Long, n As Long
   ' Modify the path in the following line so that it matches where you _
Saved LineItems.doc
   Application.ScreenUpdating = False
   ' Open the file containing the client details
   Set sourcedoc = Documents.Open(FileName:="E:\LineItems.doc")
   ' Get the number of Products = number of rows in the table of Product _
details less one
   i = sourcedoc.Tables(1).Rows.Count - 1
   ' Get the number of columns in the table of Product details
   j = sourcedoc.Tables(1).Columns.Count
   ' Set the number of columns in the Listbox to match
   ' the number of columns in the table of Product details
   ListBox1.ColumnCount = j
   ' Define an array to be loaded with the Product data
   Dim MyArray() As Variant
   'Load Product 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
Jean-Guy Marcil - 04 Nov 2006 05:54 GMT
Doctorjones_md was telling us:
Doctorjones_md nous racontait que :

> Please excuse this re-posting -- it's from a thread some weeks back
> which may have run out of steam:
[quoted text clipped - 12 lines]
> you _ Saved LineItems.doc
>    Application.ScreenUpdating = False

Why do you believe that?

Is that line highlighted when you hit "Debug" on the error message?
If it isn't this one, which it then?

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.