files directory

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
349
Office Version
  1. 365
Platform
  1. Windows
I am currently pulling a directory of files to cycle through them one by one using the following code
VBA Code:
Set fileNamesCollection2 = New Collection
MyFile2 = Dir(strP & "\*.xlsx", vbDirectory)
Do While MyFile2 <> ""
    fileNamesCollection2.Add MyFile2
    MyFile2 = Dir
Loop

This is only looking for .xlsx files but I want to set it up to look for either .xlsx or .xlsm files. IS there an easy way to do that without having to run the code twice. Can I simply search for *.xls*?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
honestly it really doesn't matter what the extension is as long as it is an Excel file. I Have some that are XLSX(in caps) some that are xlsx(lower case) and xlsm etc. The extension is indifferent to me as long as it is an excel file.
 
Upvote 0
You already had the solution. Remove vbDirectory

*.xls*
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top