Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Most efficient way to loop through a folder and find all the XLS f

I've done this a number of ways, but am wondering what the most efficient way
is to loop through a folder. I've used DIR and File Scripting Objects.
Which is the best way?

Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Most efficient way to loop through a folder and find all the XLS f

I like to use Dir for one folder and if I also want to loop through the
subfolders I use the other one

See the example code on my site



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Barb Reinhardt" wrote in message
...
I've done this a number of ways, but am wondering what the most efficient way
is to loop through a folder. I've used DIR and File Scripting Objects.
Which is the best way?

Thanks,
Barb Reinhardt


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Most efficient way to loop through a folder and find all the XLS f

I think dir is the easiest way


Folder = "c:\temp\"
FName = dir(Folder & "*.xls")
Do while FName < ""
set bk = workbooks.open(filename:=FName)
'enter your code here

bk.close savechanges:=False
FName = dir()
loop




"Barb Reinhardt" wrote:

I've done this a number of ways, but am wondering what the most efficient way
is to loop through a folder. I've used DIR and File Scripting Objects.
Which is the best way?

Thanks,
Barb Reinhardt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Most efficient way to loop through a folder and find all the XLS f

If you want to loop through only the direct children of a directory,
Dir is probably better, or at least probably faster (perceptably
faster, though, is another quesiton). However, if you want to
recursively loop through all files and folders, subfolders, subfolders
of subfolders and so on, the FileSystemObject is much easier to work
with. At http://www.cpearson.com/Excel/RecursionAndFSO.htm I describe
exactly how the FSO can be used in a recursive manner to traverse all
children of a folder.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Tue, 14 Oct 2008 11:05:01 -0700, Barb Reinhardt
wrote:

I've done this a number of ways, but am wondering what the most efficient way
is to loop through a folder. I've used DIR and File Scripting Objects.
Which is the best way?

Thanks,
Barb Reinhardt

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
VBA can't find file as it moves from folder to folder pdberger Excel Programming 1 March 8th 07 01:08 AM
For loop for each file in a folder? Kieran1028[_7_] Excel Programming 2 November 10th 04 05:11 PM
An efficient find function jdw[_2_] Excel Programming 0 August 23rd 04 05:44 PM
Loop more efficient ? farmer[_2_] Excel Programming 4 June 21st 04 06:51 AM
Efficient Search / Find MSNEWS Excel Programming 1 August 27th 03 08:34 AM


All times are GMT +1. The time now is 10:45 PM.

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"