Graham182

New Member
Joined
Jan 31, 2010
Messages
31
Hi i've got this Marco/Function

Sub get_files()
Extension = "*.CSV"
Folder = "C:\Documents and Settings\User\My Documents
First = True
RowCount = 1
Do
If First = True Then
FName = Dir(Folder & "\" & Extension)
First = False
Else
FName = Dir()
End If
If FName <> "" Then
Range("A" & RowCount) = FName
RowCount = RowCount + 1
End If
Loop While FName <> ""
End Sub

It will list everything in the My documents files
But its not searching the Subfolders and listing the name in the Directory
I know a few things about VBA but don't know what to do to ajust it to search for Subfolders can anyone help

Thanks
Graham
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
This is only returning one of the many I have in the folder?
and its also showing the path as well.
I only want the file name without the path.
I only know basic macro and VBA
hope you can help :rolleyes:
 
Upvote 0
Change the inner loop to:
Code:
            For I = 1 To .FoundFiles.Count
                Cells(I, 1).Value = Right(.FoundFiles(I), InStr(StrReverse(.FoundFiles(I)), "\") - 1)        
            Next I
Bye
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,344
Members
448,570
Latest member
rik81h

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