loop through files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
| 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?
 
The second line of code should be:

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

to open XLS files only.

--
Jim Rech
Excel MVP
| 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
| || 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?
|
|
 
Back
Top