![]() |
Reading all files in a folder
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 |
Reading all files in a folder
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 "H. Rye" wrote in message ... 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 |
All times are GMT +1. The time now is 10:12 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com