Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Opening and processing all files in a folder

Hi all,

I used to rely on Application.filesearch to open and process all files
in a given folder. However, this functionality is no longer supported
by Excel 2007. I find it extremely irritating that Microsoft does not
care about backwards compatibility, and that it does not even bother
to explain these issue clearly, nor to mention a possible alternative
(Excel VBA help is very poor and incomplete).

Anyway, I wanted to share the alternative I found, and of course I'd
be interested in hearing any feedback (I'm sure there are other
solutions):

thefile = Dir(MyFolder & "\")

FileNumber = 0
'we must specify a variable thefile=dir and then set the while
condition on it, non directly on dir
'otherwise dir would be called more times than needed
Do While thefile < ""

'full path of the file being analyzed
thefilepath = MyFolder & "\" & thefile

'counter to update the status bar showing the progress
'since this is a do... loop (and not a for ... next) we don't know
how many files are in the path
'before running the whole cycle
FileNumber = FileNumber + 1
Application.StatusBar = "Processing file " & FileNumber

Workbooks.Open (thefilepath)
CurrentlyOpenFile = ActiveWorkbook.Name

' do whatever you have to do on the file

'closes the file
Workbooks(CurrentlyOpenFile).Close saveChanges:=False ' or
SaveChanges:= True, depending on your needs

'searches the folder again to check if there is any other file
thefile = Dir()
Loop

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
Default folder for opening/saving files Dino Excel Discussion (Misc queries) 2 July 5th 07 11:28 PM
Opening different files one by one in same folder GDLGPLIC Excel Programming 1 March 13th 07 06:11 PM
opening multiple xls files in a folder sc Excel Programming 1 June 30th 06 04:00 PM
opening order macro for files in a folder Sanbitter Man[_2_] Excel Programming 1 June 24th 06 11:09 AM
"Folder Select" Dialogue - Opening multiple files from selected folder Rob[_26_] Excel Programming 2 September 30th 05 02:47 PM


All times are GMT +1. The time now is 03:30 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"