Below is my current code that pulls information I need from my Word files and copies it into an excel file. The problem is, I have many files in the M:\sales\Warranty Files 2015\ folder and this code will end after pulling the information from the first file in the folder. How do I change it to continue pulling the information from every .docx file I have in the folder?
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 = "M:\sales\Warranty Files 2015\" 'End with '\'
myFile = Dir(myPath & "*.docx")
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
Next r
Next t
ActiveWindow.Close False
myFile = Dir
Loop
xl.Visible = True
End Sub
Bookmarks