ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   loop through files (https://www.excelbanter.com/excel-programming/314240-loop-through-files.html)

newbie

loop through files
 
Hi,

I need to loop through all the files in a directory to extract data from a
specific cell but without naming the files explicitly.

Can anyone help please?

Jim Rech

loop through files
 
As a start...

Sub ProcessFiles()
Dim FileDir As String
Dim FName As String
Application.ScreenUpdating = False
FileDir = "C:\Files\"
FName = Dir(FileDir)
Do Until FName = ""
Workbooks.Open FileDir & FName, False, True
''Add extracting code...
ActiveWorkbook.Close False
FName = Dir()
Loop
End Sub

--
Jim Rech
Excel MVP
"Newbie" wrote in message
...
| Hi,
|
| I need to loop through all the files in a directory to extract data from a
| specific cell but without naming the files explicitly.
|
| Can anyone help please?



Jim Rech

loop through files
 
The second line of code should be:

FName = Dir(FileDir & "*.xls")

to open XLS files only.

--
Jim Rech
Excel MVP
"Jim Rech" wrote in message
...
| As a start...
|
| Sub ProcessFiles()
| Dim FileDir As String
| Dim FName As String
| Application.ScreenUpdating = False
| FileDir = "C:\Files\"
| FName = Dir(FileDir)
| Do Until FName = ""
| Workbooks.Open FileDir & FName, False, True
| ''Add extracting code...
| ActiveWorkbook.Close False
| FName = Dir()
| Loop
| End Sub
|
| --
| Jim Rech
| Excel MVP
| "Newbie" wrote in message
| ...
|| Hi,
||
|| I need to loop through all the files in a directory to extract data from
a
|| specific cell but without naming the files explicitly.
||
|| Can anyone help please?
|
|




All times are GMT +1. The time now is 05:44 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com