View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Philippe Oget Philippe Oget is offline
external usenet poster
 
Posts: 3
Default Listing files within a folder

Modify the code below as needed:
Note that lbBackUp is the name of a ListBox I use in an Excel W/B

DoDir g_oFSO.GetFolder(ThisWorkbook.Path & "\")
Sub DoDir(Folder)

On Error Resume Next
' On Error GoTo 0

Dim File, SubFolder

For Each File In Folder.files
' MsgBox File.Path
lbBackUp.AddItem File
Next

For Each SubFolder In Folder.SubFolders
' MsgBox SubFolder
lbBackUp.AddItem SubFolder & "\"
' DoDir g_oFSO.GetFolder(SubFolder)
Next

' If Err.Number < 0 then
' MsgBox Err.Number & Chr(13) _
' & Err.Description
' Err.Clear
' End If

End Sub

Hope that helps

Philippe
"Jeff" wrote in message
...
Lets say I have a folder named "Jeff" with 5 files in it:
A,B,C,D,E.

I would like to create VBA code in an excel worksheet that
will simply go to folder "Jeff" and list all files within
the folder. Can anyone assist? Thanks.