Results 1 to 12 of 12

code to loop through all .docx files in folder

Threaded View

rs1aj code to loop through all... 04-08-2015, 02:38 PM
Norie Re: code to loop through all... 04-08-2015, 03:06 PM
rs1aj Re: code to loop through all... 04-08-2015, 03:34 PM
Norie Re: code to loop through all... 04-08-2015, 03:37 PM
rs1aj Re: code to loop through all... 04-08-2015, 03:38 PM
Norie Re: code to loop through all... 04-08-2015, 03:59 PM
rs1aj Re: code to loop through all... 04-08-2015, 04:10 PM
Norie Re: code to loop through all... 04-08-2015, 04:26 PM
rs1aj Re: code to loop through all... 04-08-2015, 05:06 PM
rs1aj Re: code to loop through all... 04-09-2015, 09:34 AM
rs1aj Re: code to loop through all... 04-10-2015, 01:42 PM
rs1aj Re: code to loop through all... 04-12-2015, 04:41 PM
  1. #1
    Forum Contributor
    Join Date
    07-18-2014
    Location
    Missouri, USA
    MS-Off Ver
    2010
    Posts
    175

    code to loop through all .docx files in folder

    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
    Last edited by rs1aj; 04-08-2015 at 03:37 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Excel VBA code for selecting a folder then search & open specified files in that folder
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-27-2021, 03:09 AM
  2. Replies: 12
    Last Post: 03-09-2015, 05:52 PM
  3. [SOLVED] VBA Code to Move Individual Files from 1 Folder to a new Folder
    By mike.lawrie448 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 11-21-2014, 07:05 AM
  4. VBA Loop for a folder of all the files, Loop all the worksheet in each workbook
    By nanjingwoodworking in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-07-2013, 07:20 PM
  5. loop through all files in a folder except for one of them
    By masben in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2013, 10:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1