P
PAM
On 12/16/03 Doug responded to my array problems. I took
what he had, put it in my User Form and it works for a one
level array. I just CAN'T figure out how to make it
multiple arrays. Please look at code and see if anyone
can identify where the problem is. I have tried for the
last two days to make this work, but just can't get it.
code follows:
Private Sub UserForm_Initialize()
Dim sourcedoc As Document
Dim i As Integer
Dim j As Integer
Dim myitem As Range
Dim m As Long
Dim n As Long
Dim r As Integer
Dim s As Integer
Dim myitemRank As Range
Dim p As Long
Dim q As Long
Dim t As Integer
Dim u As Integer
Dim myitemOfcSym As Range
Dim v As Long
Dim w As Long
Dim x As Integer
Dim y As Integer
Dim myitemProjects As Range
Dim z As Long
Dim a As Long
Application.ScreenUpdating = False
'Open the file containing the resource details
Set sourcedoc = Documents.Open
(FileName:="c:\WINNT\Profiles\cheekp\Personal\newest
table.doc")
'Get the number of resources = number of rows in the
table less one
i = sourcedoc.Tables(1).Rows.Count - 1
'Get the number of columns in the table of resources
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 - 3
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
r = sourcedoc.Tables(1).Rows.Count - 1
'Get the number of columns in the table of resources
s = 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
ListBox2.ColumnCount = j
'Define an array to be loaded with the client data
Dim MyArrayRank() As Variant
'Load client data into MyArray
ReDim MyArrayRank(r, s)
For q = 0 To s - 3
For p = 0 To r - 1
Set myitemRank = sourcedoc.Tables(1).Cell(p + 2, q
+ 1).Range
myitemRank.End = myitemRank.End - 1
MyArrayRank(r, s) = myitemRank.Text
Next p
Next q
'Load data into ListBox1
ListBox2.List() = MyArrayRank
'Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub
Private Sub CommandButton1_Click()
Dim i As Integer
Dim Name As String
Dim Rank As String
Dim OfcSym As String
Dim Projects As String
Name = ""
Rank = ""
OfcSym = ""
Projects = ""
For i = 1 To ListBox1.ColumnCount
ListBox1.BoundColumn = i
Name = Name & ListBox1.Value & vbCr
Next i
For r = 1 To ListBox2.ColumnCount
ListBox2.BoundColumn = j
Rank = ListBox2.Value & vbCr
Next r
'UserForm1.Hide
End Sub
Thanks in advance
what he had, put it in my User Form and it works for a one
level array. I just CAN'T figure out how to make it
multiple arrays. Please look at code and see if anyone
can identify where the problem is. I have tried for the
last two days to make this work, but just can't get it.
code follows:
Private Sub UserForm_Initialize()
Dim sourcedoc As Document
Dim i As Integer
Dim j As Integer
Dim myitem As Range
Dim m As Long
Dim n As Long
Dim r As Integer
Dim s As Integer
Dim myitemRank As Range
Dim p As Long
Dim q As Long
Dim t As Integer
Dim u As Integer
Dim myitemOfcSym As Range
Dim v As Long
Dim w As Long
Dim x As Integer
Dim y As Integer
Dim myitemProjects As Range
Dim z As Long
Dim a As Long
Application.ScreenUpdating = False
'Open the file containing the resource details
Set sourcedoc = Documents.Open
(FileName:="c:\WINNT\Profiles\cheekp\Personal\newest
table.doc")
'Get the number of resources = number of rows in the
table less one
i = sourcedoc.Tables(1).Rows.Count - 1
'Get the number of columns in the table of resources
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 - 3
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
r = sourcedoc.Tables(1).Rows.Count - 1
'Get the number of columns in the table of resources
s = 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
ListBox2.ColumnCount = j
'Define an array to be loaded with the client data
Dim MyArrayRank() As Variant
'Load client data into MyArray
ReDim MyArrayRank(r, s)
For q = 0 To s - 3
For p = 0 To r - 1
Set myitemRank = sourcedoc.Tables(1).Cell(p + 2, q
+ 1).Range
myitemRank.End = myitemRank.End - 1
MyArrayRank(r, s) = myitemRank.Text
Next p
Next q
'Load data into ListBox1
ListBox2.List() = MyArrayRank
'Close the file containing the client details
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub
Private Sub CommandButton1_Click()
Dim i As Integer
Dim Name As String
Dim Rank As String
Dim OfcSym As String
Dim Projects As String
Name = ""
Rank = ""
OfcSym = ""
Projects = ""
For i = 1 To ListBox1.ColumnCount
ListBox1.BoundColumn = i
Name = Name & ListBox1.Value & vbCr
Next i
For r = 1 To ListBox2.ColumnCount
ListBox2.BoundColumn = j
Rank = ListBox2.Value & vbCr
Next r
'UserForm1.Hide
End Sub
Thanks in advance