Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Cycle through a folder of excel files

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming excel files in a folder Rhett C[_2_] Excel Discussion (Misc queries) 1 January 29th 10 05:23 AM
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
How to let Excel not to save the tmp files in the same folder? wilson lai Excel Discussion (Misc queries) 5 July 14th 08 12:03 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
Open Excel files in a folder Bob Phillips[_5_] Excel Programming 0 August 20th 03 04:47 PM


All times are GMT +1. The time now is 12:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"