1

I have a folder full of text files. In the file names, they have a file type and a unique ID. I want to grab all the files of filetype_1_ and store the directories an array so I can open the files and scan through them with another function. The part I am stuck on is filtering the results, all I want is the full directory of all the filetype_1_.

Any Idea how I can do this using Excel VBA?

filetype_1_@fileID1.txt
filetype_2_@fileID2.txt
filetype_2_@fileID3.txt
filetype_1_@fileID4.txt
filetype_1_@fileID5.txt
filetype_2_@fileID6.txt

One option I was thinking of was using the msoFileDialogFilePicker and filtering the results as *filetype_1_, then letting the user select all the files. But would I would rather do is use the msoFileDialogFolderPicker and letting VBA do the work of finding the files and storing the directory names in an array.

Any help on this would be greatly appreciated.

Community
  • 1
  • 1
Bill
  • 11
  • 1
  • Function Dir$ allows you to filter with a template and using a loop allows you to get the filenames you require one at a time. The Files property of a Folder Object will give you a collection of every file in a folder. This Files collection is in memory so it is easy and quick to extract the files you want. Dir$ is an old function. It is easy to use but limited. Folder objects are a little more difficult to use but much more powerful. – Tony Dallimore Dec 21 '14 at 23:02
  • 1
    See this post using dir with wild cards, http://stackoverflow.com/a/10382861/641067 – brettdj Dec 21 '14 at 23:03

0 Answers0