mrMadCat
New Member
- Joined
- Jun 8, 2016
- Messages
- 39
- Office Version
-
- 365
- Platform
-
- Windows
- Mobile
- Web
Hi!
I've found a macro that should copy tables from all the Word documents to one excel sheet. This is what I need but it is not working for me. It opens new excel file and stops with Runtime-Error 424 saying Object required.
There are few hundred doc files which contain some text and some tables, data from this tables I need to import. In fact I need to import only a specific cell, but this would make macro more complex.
Would appreciate any help. Thnx.
I've found a macro that should copy tables from all the Word documents to one excel sheet. This is what I need but it is not working for me. It opens new excel file and stops with Runtime-Error 424 saying Object required.
There are few hundred doc files which contain some text and some tables, data from this tables I need to import. In fact I need to import only a specific cell, but this would make macro more complex.
Would appreciate any help. Thnx.
Code:
Sub Macro1() Dim xl As Object
Set xl = CreateObject("excel.application")
xl.Workbooks.Add
xl.Visible = True
'Here put your path where you have your documents to read:
myPath = "D:\banka\" 'End with '\'
myFile = Dir(myPath & "*.doc")
xlRow = 1
Do While myFile <> ""
Documents.Open Filename:=myPath & myFile, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:=""
xlCol = 0
For Each t In ActiveDocument.Tables
For Each r In t.Rows
For Each c In r.Range.Cells
myText = c
myText = Replace(myText, Chr(13), "")
myText = Replace(myText, Chr(7), "")
xlCol = xlCol + 1
xl.ActiveWorkbook.ActiveSheet.Cells(xlRow, xlCol) = myText
Next c
xlRow = xlRow + 1
xlCol = 0
xl.ActiveWorkbook.ActiveSheet.Cells(xlRow, xlCol + 1) = myFile
xlRow = xlRow + 1
Next r
Next t
ActiveWindow.Close False
myFile = Dir
Loop
xl.Visible = True
End Sub
Last edited: