Looping thru a folder with FSO

How do I loop thru a folder called October to load all the files found within the folder.

I know what to do with the file once I locate the file - I have code to import the file.  I am somewhat familiar with the FileSystem Object, but I am struggling with:

Once I identify the folder how do I proceed to loop thru to take the next file until empty ?
upobDaPlayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
The following code will give you an idea about how to loop through the files in a folder...

'Reference to Microsoft Scripting RunTime Library must be added
Sub FsoExample()
Dim fso As FileSystemObject
Dim srcFolder As Folder
Dim xlFile As File
Dim FolderPath As String

FolderPath = "C:\Test"      'Source Folder Path
Set fso = New FileSystemObject

Set srcFolder = fso.GetFolder(FolderPath)   'Setting Source Folder

'Looping through all the files in the source folder
For Each xlFile In srcFolder.Files
    'Checking if the file in the source folder is an Excel file
    If fso.GetExtensionName(xlFile) = "xlsx" Then 'If the Excel file has .xlsx extension
        'Do whatever you want to do with that file here
        'Say you want to open the file then try this...
        Dim wb As Workbook
        Set wb = Workbooks.Open(xlFile)
    End If
Next xlFile
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
upobDaPlayaAuthor Commented:
Much appreciated..Exactly what I needed to get started
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.