ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Word to Excel (https://www.excelbanter.com/excel-programming/417043-word-excel.html)

Pepper

Word to Excel
 
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

Bob Bridges[_2_]

Word to Excel
 
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.

--- "Pepper" wrote:
...hundreds of Word file, containing a four-row, four-column table. I
need to have Excel look at each of these file and import into Excel
starting with the second row and including the third and fourth row.
It should continue until all the Word files have been processed.


Pepper

Word to Excel
 
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

"Bob Bridges" wrote:

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.

--- "Pepper" wrote:
...hundreds of Word file, containing a four-row, four-column table. I
need to have Excel look at each of these file and import into Excel
starting with the second row and including the third and fourth row.
It should continue until all the Word files have been processed.


Jean-Yves[_4_]

Word to Excel
 
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


--
Regards

Jean-Yves Tfelt
Europe


"Pepper" wrote:

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

"Bob Bridges" wrote:

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.

--- "Pepper" wrote:
...hundreds of Word file, containing a four-row, four-column table. I
need to have Excel look at each of these file and import into Excel
starting with the second row and including the third and fourth row.
It should continue until all the Word files have been processed.


Jean-Yves[_4_]

Word to Excel
 
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


--
Regards

Jean-Yves Tfelt
Europe


"Jean-Yves" wrote:

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


--
Regards

Jean-Yves Tfelt
Europe


"Pepper" wrote:

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

"Bob Bridges" wrote:

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.

--- "Pepper" wrote:
...hundreds of Word file, containing a four-row, four-column table. I
need to have Excel look at each of these file and import into Excel
starting with the second row and including the third and fourth row.
It should continue until all the Word files have been processed.


Pepper

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

Pepper

"Jean-Yves" wrote:

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


--
Regards

Jean-Yves Tfelt
Europe


"Jean-Yves" wrote:

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


--
Regards

Jean-Yves Tfelt
Europe


"Pepper" wrote:

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

"Bob Bridges" wrote:

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.

--- "Pepper" wrote:
...hundreds of Word file, containing a four-row, four-column table. I
need to have Excel look at each of these file and import into Excel
starting with the second row and including the third and fourth row.
It should continue until all the Word files have been processed.



All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com