Are you reasonably familiar with VBA? If you are I have a class module that
will do what you want. Apart from the class module all you need it about 6
lines of code to reference it and presto instant table in an array!
If you're interested post again and I'll post the code. Once you've created
the class module you can forget about it, you will not need to modify it.
This is all the code you need to load the data in your table into an array:
Dim tdInfo As clsTableData
Dim astrData() As String
' Instantiate and initialise - use table number 2
Set tdInfo = New clsTableData
strDataSource = "F:\My Templates\Table.doc"
tdInfo.Initialise strDataSource, 2
' Load data in table into array
astrData = tdInfo.Data(1, , 1)
The currently code assumes that the document containing the table is not your
current document.
HTH + Cheers - Peter
"tbotsko" <anon...@discussions.microsoft.com> wrote in news:14a7a01c3fa54
$fcf1fca0$a301...@phx.gbl:
Set pTable = Selection.Tables(1) .... or however you get a
reference to the table
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
But do you need to do this? ... if you're just pulling the information out
for use elsewhere in the document, you can just as easily use the table
itself as the source array. Note that the above code won't work if the table
contains merged or split cells, or nested tables.
"tbotsko" <anon...@discussions.microsoft.com> wrote in message
news:14a7a01c3fa54$fcf1fca0$a301...@phx.gbl...
now create a dynamic array.
Dim arr() As String 'this is this two dimensional array.
'now create a procedure which will insert the values into this array.
Sub first(ByVal row As Long, ByVal col As Long) 'function which takes rows and columns as parameter.
ReDim arr(row, col) 'dynamically increasing the size of the array.
'inserting the values into the array
For k = 1 To row
For m = 1 To col
' MsgBox (" value of k and m is :: " & k & m)
arr(k, m) = wrd.ActiveDocument.Tables(1).Cell(k, m).Range.Text
Next m
Next k
this will help u out .
from mani
Thanks for the code. Simple and concise. Now another
question. I want to look for particular values in column
three of my table/array. If the value is found, I want to
put text in a bookmark using the value in column five of
the table/array in the same row. Since the data will not
always fall in the same order, the row number will change.
Also, any suggestions for the best visual basic classes
available? I'm in the San Diego area.
Thanks.
>.
>
Rather than using bookmarks, I'd suggest you use CustomDocumentProperties.
They are easier to work with. Set up the property (File > Properties >
Custom) with a dummy value, then in the body of the document use a
DOCPROPERTY field where you want the value to appear. Then in the above code
you can use
ActiveDocument.CustomDocumentProperties("MyPropName") = pValue
When your code completes you'll need to select the document and update
fields for the new value to appear.
No idea about VB classes in the San Diego area. I'm a very long way away
from your continent.
"tbotsko" <anon...@discussions.microsoft.com> wrote in message
news:181501c3fbe3$88736e00$a401...@phx.gbl...