Populate a Word table from cells in an Excel Spreadsheet

K

Keith B

I need to write a Word VBA program than opens an excel spreadsheet and uses
a range of cells to populate a table in the Word document. I have experience
with Word VBA, but I do not know how to get information from a spreadsheet.
Can someone point me in the right direction?

Thanks,

Keith
 
J

Jezebel

Along these lines --

Dim pxlApp As Excel.Application
Dim pxlBook As Excel.Workbook
Dim pxlSheet As Excel.Worksheet

Dim pData As Variant
Dim i As Long
Dim j As Long

Set pxlApp = GetObject(, "Excel.Application")
Set pxlBook = pxlApp.Workbooks.Open("C:\Documents and
Settings\...\Book1.xls")
Set pxlSheet = pxlBook.Worksheets(1)

pData = pxlSheet.Range("C2:F4").Value
For i = 1 to 4
For j = 1 to 3
DocTable.Cell(i,j).range = pData(i,j)
Next
Next


You need to add a reference to the Excel library to the VBA project. And
don't forget to close Excel.
 

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