Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through files in folder

Status
Not open for further replies.

Simmy

Technical User
Sep 7, 2002
27
GB
Can anyone help, I need to write code that will loop through all the files in a folder and import them into an Excel sheet.

The problem is I cannot write the code to loop through all the files in the folder.

Any help is appreciated.
 

Code:
Sub ListFilesInC()
   Call ShowFolderList("c:")
End Sub

Sub ShowFolderList(folderspec)
   Dim fso       As Object
   Dim fld       As Object
   Dim fils      As Object
   Dim fil       As Object
    
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set fld = fso.GetFolder(folderspec)
   Set fils = fld.Files
   For Each fil In fils
      MsgBox fil.Name
   Next
    
   Set fil = Nothing
   Set fils = Nothing
   Set fld = Nothing
   Set fso = Nothing
End Sub
 
Thanks for the help

Will try

Regards Simmy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top