D
Doctorjones_md
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
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