Best way to combine Excel Data to Word Tables?

B

binar

Fellow Forum Members,
I am using Word 2003 for a technical manual that has close to 300 pages of
tables containing parts data. This parts data is changing all of the time
due to engineering making changes all of the time. Updating these 300 pages
of data is a major pain. My thinking is I should manage all of this data in
Excel and then perform a mail merge of some kind to update 300 pages
automatically. What is the best way to go about combining external data into
Word? I would like each cell in my Word table to match every cell in the my
Excel file one for one. What is the best function to use? Is there an
automated way to setup the cells in my Word tables so that each cell matches
a cell in my Excel table? I would like to do this right, any help will be
greatly appreciated. Thanks.
 
E

Ed from AZ

Why wouldn't a link from the Excel worksheet range into the Word
document work?

If that just won't do, then you may have to resort to a brute-strength
method I have employed: as long as your Word table and your Excel
range are the same size, you could have a macro that scanned through
each cell one by one and wrote the data into Word:
For 1 To cntRows
For 1 To cntCols
WDtblcell(cntRows, cntCols) = XLcell(cntRows, cntCols)
Next
Next

Ed
 
E

Ed from AZ

You really don't have to go into DAO with just Word and Excel. If you
were programming Word and Excel from outside the apps from VB or
Access, then that may be your answer. But if you are only using Word
and Excel, then the Visual Basic for Applications macro language
provided with these programs is powerful enough to do almost anything
you want.

For instance, I have an Excel spreadsheet "linked" to a Word report.
("Linked" is in quotes because it's not a link the way Microsoft uses
it; it's simply that these two go together.) At the moment, every
time I update this report, I need to update about 150 separate numbers
in various places in the document, plus pull in two whole-page tables
and import and embed five other Excel files. I click one button and
the process takes about 45 seconds (I have a slow computer!). It's
all done with macros - no ADO required.

The set-up was a bit tedious, but the time savings every two weeks
when I put out this report is well worth it!

Anyway, that's my experience.
Ed
 
B

binar

Ed,
Thanks for the help. I have a followup question regarding this approach you
are recommending. In EXCEL each cell is identified A1, A2, B1, B2, C1, etc...
In Word the cells in tables don't really have such reference designators. How
will a macro created in Excel accomplish the task of copying data from cells
A1:A4 and transfer it to the same cells located in a Word Table where such
reference designators are not used? I am not to clear on how the CntRows and
CntCols will accomplish this. Any info or links will be greatly appreciated.
 
E

Ed from AZ

You can refer to cells in a Word table by Cell(row, column).

The "cntRows" and "cntCols" I used before is what is known as "air
code" or "psuedo-code" - it's not a real VBA item, but a reference to
something. The same with the other terms. In this case, that portion
of the maco might look something like:

Dim cntRows As Long
Dim cntCols As Long
Dim x As Long, y As Long
Dim WDtbl As Word.Table

cntRows = WDtbl.Rows.Count
cntCols = WDtble.Columns.Count

For x = 1 To cntRows
For y = 1 To cntCols
WDtbl.Cell(x, y) = xlWKS.Cells(x, y)
Next y
Next x

The whole macro, though, will also contain setting objects to the Word
document and table, the Excel worksheet, and possible other objects as
required by your code. Specific properties are also going to depend
on your requirements. If you search the
Microsoft.Public.Word.VBA.General and
Microsoft.Public.Excel.Programming newsgroups, there's lots of
examples there for you.

Here's some other references for you:
http://word.mvps.org/FAQs/InterDev/ControlXLFromWord.htm
http://word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm
http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

Word Help:
Range Object
Table object
Cell Object

Excel Help:
Worksheet Object
Range Object
Cells Property
Referring to Cells by Using Index Numbers
Looping Through a Range of Cells


Ed
 
C

Curt

Is it possible to use this count idea to control area that word searches in
an excel wksheet? I am trying to stop word from searching the full 6000 rows
200 is plenty. I am fairly good in excel but a little lost in word.
Thank You
 

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