Importing data from word to Excel

Angiec50

New Member
Joined
Oct 8, 2009
Messages
29
I need to import data from a table in a word document within a specific section (i.e Page 4, headed section 4a). However, there are 300 different word documents that I need to import into one spreadsheet.

Does anyone have any ideas on the quickest way of doing this without the user having to go in manually to select the data? :confused:

Thanks

Angie
 
HTH to get you started. Dave
Code:
Sub WordTableToXL()
Dim WdApp As Object, wdDoc As Object
Dim iRow As Long, iCol As Integer

On Error GoTo Erfix
Set WdApp = CreateObject("Word.Application")
'adjust file path to suit
Set wdDoc = WdApp.Documents.Open(Filename:="D:\test.doc")
If wdDoc.Tables.Count = 0 Then
MsgBox "This document contains no tables"
GoTo Erfix
End If
'adjust table # to suit
With wdDoc.Tables(1)
For iRow = 1 To .Rows.Count
    For iCol = 1 To .Columns.Count
    On Error Resume Next
    'adjust XL address below to suit
    Sheets("sheet1").Cells(iRow, iCol) = _
    WorksheetFunction.Clean(.Cell(iRow, iCol).Range.Text)
    On Error GoTo 0
    Next iCol
Next iRow
End With
Set wdDoc = Nothing
WdApp.Quit
Set WdApp = Nothing
Exit Sub

Erfix:
On Error GoTo 0
MsgBox "Error"
Set wdDoc = Nothing
WdApp.Quit
Set WdApp = Nothing
End Sub
 
Upvote 0
Thanks Dave.

I have tried this and for once I have got something working pretty much straight away :-). However, I have just realised that the word documents I have been given are forms and so the table I want to import has tick boxes that have been completed. Is there anyway I can also import the answers?. I presume that I would need to change the macro for each of the 300 word documents as well. I might just get the user to transfer it manually - teach them right for creating it in word in the first place :laugh:
 
Upvote 0

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