hello everyone! i hope you can help me with my problem.I have a word file with lots of tables in it and want to import it to excel but only import specific columns from each table.What is more, i want to rename some of the data if a specific conditions exists.
this a sample of the word file (the actual file is over 200 pages) :https://dl.dropbox.com/u/13471344/test.doc (the .doc is in Greek)
1. i want to insert only certain column of each table (based on the column heading)
Which means read the header of each column - of each table - and only insert certain columns from each table (the decider being the header name)
2. i want to rename the data of the column:
for example if column has the data:
[TABLE="width: 50"]
<tbody>[TR]
[TD]381a.1[/TD]
[/TR]
[TR]
[TD].2[/TD]
[/TR]
[TR]
[TD].3[/TD]
[/TR]
[TR]
[TD].4[/TD]
[/TR]
[TR]
[TD].5[/TD]
[/TR]
</tbody>[/TABLE]
i want to read the first cell and then rename the rest cells as:
[TABLE="width: 50"]
<tbody>[TR]
[TD]381a.1[/TD]
[/TR]
[TR]
[TD]381a.2[/TD]
[/TR]
[TR]
[TD]381a.3[/TD]
[/TR]
[TR]
[TD]381a.4[/TD]
[/TR]
[TR]
[TD]381a.5[/TD]
[/TR]
</tbody>[/TABLE]
I have managed to create the macro for inserting all the tables to excel (with the help of Google and my minor skills) but do not know how to do the rest ...
this is the module so far...
<code><o> </o></code>
thank you in advance!
this a sample of the word file (the actual file is over 200 pages) :https://dl.dropbox.com/u/13471344/test.doc (the .doc is in Greek)
1. i want to insert only certain column of each table (based on the column heading)
Which means read the header of each column - of each table - and only insert certain columns from each table (the decider being the header name)
2. i want to rename the data of the column:
for example if column has the data:
[TABLE="width: 50"]
<tbody>[TR]
[TD]381a.1[/TD]
[/TR]
[TR]
[TD].2[/TD]
[/TR]
[TR]
[TD].3[/TD]
[/TR]
[TR]
[TD].4[/TD]
[/TR]
[TR]
[TD].5[/TD]
[/TR]
</tbody>[/TABLE]
i want to read the first cell and then rename the rest cells as:
[TABLE="width: 50"]
<tbody>[TR]
[TD]381a.1[/TD]
[/TR]
[TR]
[TD]381a.2[/TD]
[/TR]
[TR]
[TD]381a.3[/TD]
[/TR]
[TR]
[TD]381a.4[/TD]
[/TR]
[TR]
[TD]381a.5[/TD]
[/TR]
</tbody>[/TABLE]
I have managed to create the macro for inserting all the tables to excel (with the help of Google and my minor skills) but do not know how to do the rest ...
this is the module so far...
Code:
Option Explicit
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 resultRow As Long
Dim tableStart As Integer
Dim tableTot As Integer
On Error Resume Next
ActiveSheet.Range("A:AZ").ClearContents
wdFileName = Application.GetOpenFilename("Word files (*.doc),*.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
tableTot = 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 the table to start from", "Import Word Table", "1")
End If
resultRow = 4
For tableStart = 1 To tableTot
With .tables(tableStart)
'copy cell contents from Word table cells to Excel cells
For iRow = 1 To .Rows.Count
For iCol = 1 To .Columns.Count
Cells(resultRow, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
Next iCol
resultRow = resultRow + 1
Next iRow
End With
resultRow = resultRow + 1
Next tableStart
End With
End Sub
<code><o> </o></code>
thank you in advance!