PDA

View Full Version : [SOLVED:] How to list all the files in a folder?



phille
08-07-2014, 02:56 AM
I'm new here on the forum and a VBA noop.

I'm looking for a code to list all files in a folder.

and this for mac.

thanks

ranman256
08-07-2014, 12:12 PM
'oooppps I missed the MAC thing.



Public Sub ListAllFilesInDir(ByVal pvDir)
Dim vFil, vTargT
Dim fso
Dim oFolder, oFile

On Error GoTo errImp
If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(pvDir)
For Each oFile In oFolder.Files
vFil = pvDir & oFile.Name
'If InStr(vFil, ".xls") > 0 Then 'ONLY DO EXCEL FILES

debug.print oFile.name

'endif
Next
Set fso = Nothing
Set oFile = Nothing
Set oFolder = Nothing
Exit Sub

phille
08-08-2014, 07:05 AM
thanks