Dim Mypath as string, MyName as String,iCount as integer iCount=0 MyPath = "M:\MUSIC\MP#MUSICALBUMS" ' Set the path. MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry. Do While MyName <> "" ' Start the loop. ' Ignore the current directory and the encompassing directory. If MyName <> "." And MyName <> ".." Then ' Use bitwise comparison to make sure MyName is a directory. If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then Debug.Print MyName ' Display entry only if it iCount=iCount+1 End If ' it represents a directory. End If MyName = Dir ' Get next entry. Loop debug.print "No.of Folders in the selected path : " & iCount
Sub Ck() Dim strStartPath As String strStartPath = "M:\MUSIC\MP3MUSICALBUMS" 'ENTER YOUR START FOLDER HERE ListFolder strStartPath End Sub Sub ListFolder(sFolderPath As String) Dim FS As New FileSystemObject Dim FSfolder As Folder Dim subfolder As Folder Dim i As Integer Set FSfolder = FS.GetFolder(sFolderPath) For Each subfolder In FSfolder.SubFolders DoEvents i = i + 1 'added this line Cells(i, 1) = subfolder 'commented out this one 'Debug.Print subfolder Next subfolder Set FSfolder = Nothing 'optional, I suppose MsgBox "Total sub folders in " & sFolderPath & " : " & i End Sub
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE