dj44
02-27-2016, 06:27 PM
Folks,
hope all you great people are doing good today:)
I am trying to make a multidimensional array from my table.
I am trying to import the contents of the table into the array - I am not sure if I am explaining it correctly.
15487
How do I point my array to a table.
You see I have lots of tables and then I have some vba macros that use arrays - so i need to learn the skill of pointing an array to a table.
Now I have been trying to get my array to work for a while, but its gone bust.:doh:
Sub MultiDimensionalArrayTable()
Dim oRng As Word.Range
Dim lngIndex As Long
Dim FindTVD() As String
Dim AppendFSH() As String
Tablelocation As string
Tablelocation = "C\Users\DJ-PC\Desktop\TVDTable.doc"
Set Document = ActiveDocument
Set Tablelocation = Documents.Open(FileName:=strpath, Visible:=False)
'Column 1 - Find TVD
'FindTVD = Split(" TVD 1028,TVD 9084,TVD 9084")
FindTVD = ActiveDocument.Tables(1).Cell(i, 1).Range.Text
'Column 2 - Append the FSH
AppendFSH = ActiveDocument.Tables(1).Cell(i, 2).Range.Text
'AppendFSH = Split("FSH073,FSH045,FSH732,FS345")
For lngIndex = 0 To UBound(FindTVD)
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindTVD(lngIndex)
.MatchWholeWord = True
' do the important work
.Replacement.Text = FindTVD(lngIndex) & AppendFSH(lngIndex)
.Execute Replace:=wdReplaceAll
End With
Next
lbl_Exit:
Exit Sub
End Sub
I saw this and got the idea that I can point my array to the table.
But this code is ancient, I couldn't get this to work with my table above
Sub arraytest()
Dim pTable As Word.Table
Dim pArray() As Variant
Dim pRow As Long
Dim pColumn As Long
Set pTable = Selection.Tables(1)
ReDim pArray(1 To pTable.Rows.Count, 1 To pTable.Columns.Count)
For pRow = 1 To pTable.Rows.Count
For pColumn = 1 To pTable.Columns.Count
pArray(pRow, pColumn) = pTable.Cell(pRow, pColumn)
Next
Next
Debug.Print pArray(2, 2) 'prints content of table
'Debug.Print pArray(1, 2) 'prints content of table
End Sub
I got stuck here trying to combine these 2.
https://groups.google.com/forum/m/#!topic/microsoft.public.word.vba.general/oUJNJC8YUVU
Folks do let me know how i can point this mulitdimendional array to my external table.
I thank you for your expert advice on my naivete multidimensional array offering
& for your kind valuable time :grinhalo:
Enjoy your weekend
DJ
hope all you great people are doing good today:)
I am trying to make a multidimensional array from my table.
I am trying to import the contents of the table into the array - I am not sure if I am explaining it correctly.
15487
How do I point my array to a table.
You see I have lots of tables and then I have some vba macros that use arrays - so i need to learn the skill of pointing an array to a table.
Now I have been trying to get my array to work for a while, but its gone bust.:doh:
Sub MultiDimensionalArrayTable()
Dim oRng As Word.Range
Dim lngIndex As Long
Dim FindTVD() As String
Dim AppendFSH() As String
Tablelocation As string
Tablelocation = "C\Users\DJ-PC\Desktop\TVDTable.doc"
Set Document = ActiveDocument
Set Tablelocation = Documents.Open(FileName:=strpath, Visible:=False)
'Column 1 - Find TVD
'FindTVD = Split(" TVD 1028,TVD 9084,TVD 9084")
FindTVD = ActiveDocument.Tables(1).Cell(i, 1).Range.Text
'Column 2 - Append the FSH
AppendFSH = ActiveDocument.Tables(1).Cell(i, 2).Range.Text
'AppendFSH = Split("FSH073,FSH045,FSH732,FS345")
For lngIndex = 0 To UBound(FindTVD)
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindTVD(lngIndex)
.MatchWholeWord = True
' do the important work
.Replacement.Text = FindTVD(lngIndex) & AppendFSH(lngIndex)
.Execute Replace:=wdReplaceAll
End With
Next
lbl_Exit:
Exit Sub
End Sub
I saw this and got the idea that I can point my array to the table.
But this code is ancient, I couldn't get this to work with my table above
Sub arraytest()
Dim pTable As Word.Table
Dim pArray() As Variant
Dim pRow As Long
Dim pColumn As Long
Set pTable = Selection.Tables(1)
ReDim pArray(1 To pTable.Rows.Count, 1 To pTable.Columns.Count)
For pRow = 1 To pTable.Rows.Count
For pColumn = 1 To pTable.Columns.Count
pArray(pRow, pColumn) = pTable.Cell(pRow, pColumn)
Next
Next
Debug.Print pArray(2, 2) 'prints content of table
'Debug.Print pArray(1, 2) 'prints content of table
End Sub
I got stuck here trying to combine these 2.
https://groups.google.com/forum/m/#!topic/microsoft.public.word.vba.general/oUJNJC8YUVU
Folks do let me know how i can point this mulitdimendional array to my external table.
I thank you for your expert advice on my naivete multidimensional array offering
& for your kind valuable time :grinhalo:
Enjoy your weekend
DJ