View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default Cycle through a folder of excel files

Hi Chet

Try this for the files in the folder C:\Data

Sub TestFile1()
Dim mybook As Workbook
Dim FNames As String
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir
MyPath = "C:\Data"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Do While FNames < ""
Set mybook = Workbooks.Open(FNames)

'your code
MsgBox mybook.Name

mybook.Close False
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Chet" wrote in message ...
Does anyone have a way to cycle throught a folder of
files that are on my computer?

What I want to do is open the first file in a specific
folder, perform a couple of functions, save, close and
then open the next file in line to perform the same set
of functions.

I have a alot of files and don't want to have to open
each one seperatly.

Chet