0

I currently have this code that finds the *csv files in a folder how can I change it where it can find all the *csv files in the sub folders.

folderPath = InputBox("Enter Folder Name where CSV files are.")
'MsgBox folderPath

If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
fileName = Dir(folderPath & "*.csv")

Do While fileName <> ""
  Application.ScreenUpdating = False
    Set wB = Workbooks.Open(folderPath & fileName)

Basically, look for all *.csv files in the given location.

fali
  • 57
  • 1
  • 9
  • Did your research lead you to [this](https://stackoverflow.com/questions/9827715/get-list-of-sub-directories-in-vba), or [this](https://stackoverflow.com/questions/14245712/cycle-through-sub-folders-and-files-in-a-user-specified-root-directory), or [this](https://stackoverflow.com/questions/22645347/loop-through-all-subfolders-using-vba)? What did you try? – BigBen Jun 02 '21 at 18:12
  • @BigBen I researched and tried few things without changing too much of the above code. After that I decided to ask here. I'll continue to research and see if I can figure it out. – fali Jun 02 '21 at 18:42
  • 1
    As a function returning a Collection of File objects: https://stackoverflow.com/questions/58883838/getting-a-list-of-filtered-filenames-from-directory-and-sub-directories-into-an/58884001#58884001 Also be nice to your users and have them pick a folder instead of typing the path: https://wellsr.com/vba/2016/excel/vba-select-folder-with-msoFileDialogFolderPicker/ – Tim Williams Jun 02 '21 at 18:42

0 Answers0