Importing Word table in to excel

rahulnair871

New Member
Joined
May 22, 2013
Messages
1
Hi,

In my daily line of work, I require to split a MS word table in to smaller tables each row being put in to a new word document.

I think it will be a lot easier if a process is set up for this and tried using an excel Macro to do my splits.

3 steps should do this:

1) Import the table in .doc file to excel
2) perform splits as per my need
3)Export back to .doc files with split tables

I am currently in step 1 and i have scanned this forum to get a useful macro that imports word table in to excel. Thanks to the creator of the below.

Sub ImportWordTable()
Dim wdDoc As Object
Dim wdFileName As Variant
Dim TableNo As Integer 'table number in Word
Dim iRow As Long 'row index in Excel
Dim iCol As Integer 'column index in Excel
'Dim iTab As Integer
wdFileName = Application.GetOpenFilename("Word files (*.doc),*.doc,(*.docx),*.doc", , _
"Browse for file containing table to be imported")
If wdFileName = False Then Exit Sub '(user cancelled import file browser)
Set wdDoc = GetObject(wdFileName) 'open Word file
With wdDoc
TableNo = wdDoc.tables.Count
If TableNo = 0 Then
MsgBox "This document contains no tables", _
vbExclamation, "Import Word Table"
ElseIf TableNo > 1 Then
TableNo = InputBox("This Word document contains " & TableNo & " tables." & vbCrLf & _
"Enter table number of table to import", "Import Word Table", "1")
End If
'For iTab = 1 To TableNo
With .tables(TableNo)
'copy cell contents from Word table cells to Excel cells
For iRow = 1 To .Rows.Count
For iCol = 1 To .Columns.Count
Cells(iRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
Next iCol
Next iRow
End With
'Next iTab
End With
Set wdDoc = Nothing
End Sub

Speaking of the issue:

The first column of the table is numbering eg: Step 1.1, Step 1.2 ...
The macro is unable to read the numbering of word and import it in to target excel. The result is blank cells in the excel.

Is it possible to read the numbering from MS Word table and import it as such?
Please advise.

Sample data:
---------------

Step 1.1</SPAN></SPAN> </SPAN>
data col1
data col2
data col 3
data col4
data col5
Step 1.2</SPAN></SPAN> </SPAN>
data 1
data 2
data 3
data 4
data 5

<TBODY>
</TBODY>


Regards,
Rahul
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,214,786
Messages
6,121,553
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top