Reading all files in a folder

  • Thread starter Thread starter H. Rye
  • Start date Start date
H

H. Rye

Hi

I have stored a number of workbooks (lets say 50 files containing timesheets
for each emloyee in my company) in a folder. All workbooks are structurally
the same. Is there a way I can make my program detect all these files an
read the content into a new file. Of. course I can hardcode everey singel
filename, but that appears to be a bad solution to me.

Regards,


Havard
 
Havard,

Try something like the following:

Dim FName As String
Dim WB As Workbook
Const FOLDER_NAME = "C:\Temp" '<<< CHANGE

ChDrive FOLDER_NAME
ChDir FOLDER_NAME
FName = Dir("*.xls")
Do Until FName = ""
Set WB = Workbooks.Open(Filename:=FName)
'
' do something with WB
'
WB.Close SaveChanges:=False 'or True
FName = Dir()
Loop


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top