+ Reply to Thread
Results 1 to 2 of 2

Need Macro to open and extract data from from multiple txt files

  1. #1
    Registered User
    Join Date
    05-02-2012
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    1

    Need Macro to open and extract data from from multiple txt files

    I need a macro to open all txt files in multiple folders and sub folders so that I can extract data before closing the files. My folder structure is "MainFolder/SubFolder1/SubSubfolder1". The txt files are within the SubSubFolders and I typically have 3 SubFolders and 24 SubSubFolders (3 days of data with a separate folder for each our of the day). I also need to only open the txt files as there are also csv files which I need to ignore. Any help would be appreciated. I effectively want to open each txt file (space delimited), extract several cells to a spreadsheet, close the file, and then move to the net file and repeat until all files have had their data extracted. Thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Need Macro to open and extract data from from multiple txt files

    This calls for the FileSystemObject to recursively loop through files in the folders looking for .txt files. Google "FileSystemObject recursive folders vba" as a starting point. The program could either open and process each found .txt file immediately in the recursive subroutine, or build a list of .txt files (in a dynamic array, or easier added to a worksheet column) to be opened and processed separately. For opening the .txt files, open one manually with the macro recorder running to generate the code, which can be adapted for opening any .txt file.
    Post responsibly. Search for excelforum.com

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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