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:
---------------
<TBODY>
</TBODY>
Regards,
Rahul
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