How to read data from another Word file?

C

cyberdude

Hi,

In one of my previous posts, I asked people to help me on the
following:

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
I need to work on a multi-dimensional string-type array in VBA. Let
me call it object_list and assume that it has 3 dimensions for the
time being.

Therefore, I'll declare it as

Dim object_list(n, n, n) as string
where n is the length of one of the dimensions.

Now, the tricky thing is that elements of object_list need to be
updated frequently, either about the number of elements in a
dimension
or content of the elements themselves. To facilitate this kind of
updating, I plan to place and do all the editing of the 3 columns of
elements in an Excel worksheet first and then load the 3 columns of
elements into array object_list. The elements are supposed to be put
into columns A, B and C in an Excel worksheet. For each action of
this kind, the number of elements for each dimension, that is n, may
vary. So, may I ask how to achieve the above by writing a VBA macro
to load the 3 columns of elements from an Excel worksheet into array
object_list whose length may change on each occasion? Thanks.
I think the above task may be too difficult that I have received no
response so far.

Now, I am changing my strategy. I would put the 3 columns of data in
a table
in a Word document and treat this Word document as the data source.
Let me call this document "DocA". Would the task become easier after
the change? The last unsolved problem now is how to write the VBA
code to open "DocA" containing the 3-column table, read the data
inside the 3-column table and put the data into array object_list
which is inside another Word document, say "DocB". Your help will be
much appreciated. Thanks.

Mike
 
C

Cindy M.

Hi Cyberdude,
I think the above task may be too difficult that I have received no
response so far.
No, it's not a question of difficulty. It's a question of working with
Excel. This is a Word group, and your Excel-oriented question isn't
really straight-forward to deal with. Added to that, your problem
description isn't very clear about the expected content of the Excel
workbook.

FWIW, my gut feeling was (and is) that it would be most efficient to
access the data in the workbook using a data connection, rather than
automating Excel. But there's some question in my mind about the best
way to do this when having to deal with three columns, of different -
and varying - lengths.

You might have better luck getting some pointers on this approach in
the excel.programming newsgroup.

The approach for working with a Word table would, in principle, not be
much different from automating Excel (meaning it would be slower).
You'd need to "walk" down the cells adding the cell content to the
array as you go. A major difference is that in Word you'd need to cut
the last two characers off, as they'll be the end-of-cell markers.

As to the arrays, I'm thinking it would probably make sense to just
count the number of rows in the table and use that value for each
dimension. Put zero-length strings in the members you don't need (no
data in the cells) and test for that in your code. That would probably
be more efficient than needing to use Redim Preserve in every pass
through the loop that fills the array.
Now, I am changing my strategy. I would put the 3 columns of data in
a table
in a Word document and treat this Word document as the data source.
Let me call this document "DocA". Would the task become easier after
the change? The last unsolved problem now is how to write the VBA
code to open "DocA" containing the 3-column table, read the data
inside the 3-column table and put the data into array object_list
which is inside another Word document, say "DocB". Your help will be
much appreciated.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

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