Word to Excel

P

Pepper

I have hundreds of Word file, containing a four row, four column table. I
need to have Excel look at each of these file and import/copy-paste or what
ever is required into Excel starting with the second row and includint the
third and fourth row.
It should continue until all the Word files have been processed.

Please save me days of work.
Thanks

Pepper
 
B

Bob Bridges

Hi, Pepper. Do you want to learn how to write a program like that, or just
have some code you can take and run? I'm a teach-a-man-to-fish kind of guy,
myself, so I offer the former, but if you prefer not to go to that kind of
trouble I'm sure there are others here (well, pretty sure) that'll just hand
you some code.
 
P

Pepper

Thank you Bob, my answer is both.
I am eager to learn VBA to help us automate Excel but right now my needs are
immediate. Any help with this project will be greatly appreciated.
Pepper
 
J

Jean-Yves

Hi Pepper,

To proccess all files in a folder, The Dir function is what you need.

To read word file,
1. make a reference to word in via VBA Tools/References
2. In word, a table can be refererd to by its index and the content using
row an column number

3. the sub
Sub WordToExcel()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Integer
Dim strFilename As String
Dim temp As String

Set wdApp = New Word.Application
'initialise counter
x = 1
'search for first file in directory
strFilename = Dir("C:/Temp/*.doc") 'amemd folder name
Do While strFilename <> ""
Set wdDoc = wdApp.Documents.Open(strFilename)
temp = wdDoc.Tables(1).Cell(2, 1).Range.Text 'read word cell
Range("A2").Offset(x, 0) = temp
temp = wdDoc.Tables(1).Cell(2, 2).Range.Text 'read word cell
Range("A2").Offset(x, 1) = temp
'etc


wdDoc.Close
x = x + 1
strFilename = Dir
Loop

End Sub
 
J

Jean-Yves

Just forgot some cleaning at the end
Sub WordToExcel()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim x As Integer
Dim strFilename As String
Dim temp As String

Set wdApp = New Word.Application
'initialise counter
x = 1
'search for first file in directory
strFilename = Dir("C:/Temp/*.doc") 'amemd folder name
Do While strFilename <> ""
Set wdDoc = wdApp.Documents.Open(strFilename)
temp = wdDoc.Tables(1).Cell(2, 1).Range.Text 'read word cell
Range("A2").Offset(x, 0) = temp
temp = wdDoc.Tables(1).Cell(2, 2).Range.Text 'read word cell
Range("A2").Offset(x, 1) = temp
'etc


wdDoc.Close
x = x + 1
strFilename = Dir
Loop
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub
 
P

Pepper

Thank you Jean-Yves,
I will give your code a try a let you know how I make out.

Pepper
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top