Need help putting Word Table data into an Array

M

MikeZz

Hi,
I open a .rtf file in Word which I want to pull data from.

The document has a large number of similarly formatted tables of which I
want to put the data into an array.

In my Code below, I use the selection.find command to find a string which
only occurs in certain tables. After it finds and selects that cell, I want
to have VBA put that entire table into an array. Then repeat by doing
another search to find another table and do the same thing.

I do 99% of my VBA from excel and this particular macro is actually based
from an Excel Workbook. However, if someone can give me the basic VBA that
will work in VBA Word, I can figure out how to convert it to work from Excel.

Basic info I'm thinking would need....
(Keeping in mind that I don't know much about Word VBA)
How do I reference the current table?
How do I get the # of rows & columns of the active table,
Can I use some code like:

For r = 1 to activetable.rows.count
For c = 1 to activetable.cols.count
code to put cell(r,c) into array
Next C
Next R

Thanks for the help!
MikeZz


======= Section of MY EXISTING CODE ========


Set oWord = GetObject(, "Word.Application")

oWord.Visible = True
oWord.Activate

Dim myRange As Word.Range
Set myRange = ActiveDocument.Range

oWord.Activate
Set oDoc = oWord.ActiveDocument
oWord.Selection.Find.ClearFormatting
With oWord.Selection.Find
.Text = "Product/DRD FAM"
.Forward = True
.Wrap = wdFindContinue
End With
oWord.Selection.Find.Execute

'Selects the proper cell in a table.
'Now want VBA to put that entire table into an array.
 
J

Jonathan West

Dim myArray() As String
ReDim myArray(1 to activetable.rows.count, 1 to activetable.columns.count

For r = 1 to activetable.rows.count
For c = 1 to activetable.columns.count
myArray(r, c) = ActiveTable.Cell(r, c).Range.Text
myArray(r, c) = Left$(myArray(r, c), Len(myArray(r, c)) - 2)
Next C
Next R
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top