Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way that I can automate the copying of information from Microsoft Word tables to Microsoft Excel tables?

share|improve this question
    
what do you mean? You have a table in Excel that when changes are made you want updated to in Word? –  KronoS Feb 27 '13 at 22:40

1 Answer 1

Yes, this is very much possible. As I demonstrated just yesterday, you can use Word and Excel automation via VBScript to do anything VBA supports. Try the following VBS script:

Option Explicit

Dim objWord, objDoc, objExcel, objSheet, tbl, srcRow, dstRow, col, cell

Set objWord = CreateObject("Word.Application")
objWord.Visible = False
objWord.DisplayAlerts = False
objWord.Documents.Open "C:\MyDoc.docx", False, True ' path, confirmconversions, readonly
Set objDoc = objWord.ActiveDocument

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False
objExcel.Workbooks.Add
Set objSheet = objExcel.ActiveSheet

dstRow = 0
For Each tbl In objDoc.Tables
    For srcRow = 1 To tbl.Rows.Count
        col = 0
        For Each cell In tbl.Rows(srcRow).Cells
            col = col + 1
            objSheet.Cells(dstRow+srcRow, col).Value = Left(cell.Range.Text, Len(cell.Range.Text)-1)
        Next
    Next
    dstRow = dstRow + SrcRow
Next

objWord.Quit 0 ' wdDoNotSaveChanges
Set objWord = Nothing
Set objDoc = Nothing

objExcel.ActiveWorkbook.SaveAs "C:\MyBook.xlsx"
objExcel.Quit
Set objExcel = Nothing
Set objSheet = Nothing

MsgBox "All table data copied from document to workbook!"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.