vba-loop through subfolders

ER_Neha

Board Regular
Joined
Jul 25, 2020
Messages
130
Office Version
  1. 365
Platform
  1. Windows
How to loop through folders and their sub folders in vba. I tried using this code but its not working for me. my folder variable gets the correct name i.e. "d:\neha" but my variable sf for subfolder is not working
VBA Code:
Sub ShowFolderList()
    Dim fso, folder, f1, sf
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder("d:\neha")
    Set sf = folder.subfolders
    For Each f1 In sf
       If f1.name = "n1" Then
        MsgBox " found"
        End If
       
    Next
   
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Not End Sub, just End
Hello Fluff, thank u it worked the way i wanted, but can you please help me to check how much time the total procedure took, i tried using timer function , but its not functioning properly.
 
Upvote 0
How did you setup the timer?
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

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