Import tables from Word into Excel
How to import tables from a Word document into Excel using VBA
Dim ws As Worksheet
Dim WordFilename As Variant
Dim Filter As String
Dim WordDoc As Object
Dim tbNo As Long
Dim RowOutputNo As Long
Dim RowNo As Long
Dim ColNo As Integer
Dim tbBegin As Integer
"Word File Old (*.doc), *.doc,"
ws.Cells.ClearContents
'if you only want to clear a specific range, replace .Cells with the range that you want to clear
WordFilename = Application.GetOpenFilename(Filter, , "Select Word file")
Set WordDoc = GetObject(WordFilename)
MsgBox "This document contains no tables"
End If
RowOutputNo = 1
For tbBegin = 1 To tbNo
ws.Cells(RowOutputNo, ColNo) = Application.WorksheetFunction.Clean(.cell(RowNo, ColNo).Range.Text)
Next ColNo
RowOutputNo = RowOutputNo + 1
Next RowNo
End With
RowOutputNo = RowOutputNo
Next tbBegin
End Sub
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
Worksheet Name: Have a worksheet named Analysis.
ADJUSTABLE PARAMETERS
Worksheet Name: Select the worksheet where you want to import the data by changing the Analysis worksheet name in the VBA code to any worksheet in the workbook.
Message Box: Change the message that will be displayed if there are no tables in the Word document by replacing the current text in the double quotation marks "This document contains no tables".
This tutorial explains and provides step by step instructions on how to import tables from a Word document into Excel using VBA.
The VBA code in this tutorial will open a browser window which will allow you to select the Word document which contains the tables that you want to import into Excel. Once the Word document is selected and the 'Open' button clicked, the VBA code will import into Excel all of the data that is captured in the tables.