LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Do While only does once

You are misinterpreting the term directory. If he is renaming the file, he
is changing the data stored in the directory section of the file management
system.

http://support.microsoft.com/default...89&Product=xlw
OFF2000: Endless Loop When Macro Modifies Files in a Folder

However, renaming the files may not cause the problem - I said it is
possible.


some sample code on looping through a directory
http://support.microsoft.com/default...24&Product=xlw
Macro to Loop Through All Files in a Folder (Directory)

http://support.microsoft.com/default...69&Product=xlw
XL2000: How to Programmatically Display All Files in a Folder


Here is some code that builds an array of filenames:

Sub Tester10()
LookForfiles "C:\Data"
End Sub
Sub LookForfiles(ByVal DirToSearch As String)
Dim i As Long
Dim Files() As String
Dim Contents As String
Dim counter As Long

counter = 0
DirToSearch = DirToSearch & "\"
Contents = Dir(DirToSearch, vbDirectory)
Do While Contents < ""
If Contents < "." And Contents < ".." Then
If (GetAttr(DirToSearch & Contents) And vbDirectory) < vbDirectory _
Then
If InStr(Contents, ".xls") Then
counter = counter + 1
ReDim Preserve Files(1 To counter)
Files(counter) = DirToSearch & Contents
End If
End If
End If
Contents = Dir()
Loop
If counter = 0 Then Exit Sub
For i = 1 To counter
Debug.Print Files(i)
Next i
End Sub

--
Regards,
Tom Ogilvy



"Bob Phillips" wrote in message
...
Mike,

I am missing what Tom says myself. I don't think that he is saying that

you
are changing the directory, but as I don't see that he is doing it either,

I
don't get the point. However, assuming that you want to process all files
called *.WMV in the directory, Tom's amendment seems to do the job fine.
Can't see how an array will help in this case.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Mike Williams" wrote in message
...
Thanks, Tom & Bob. I couldn't make out in the documentation on Do While
just where the thing got incremented; it's more obvious with For Each

Next
statements. I'm assuming it's in the "file = ..." line Tom added,

quoted
below -- although I still don't get how that line works. One additional
question. I didn't realize I was changing the directory at all, and I
certainly don't need to. Did I do that somewhere, or is it in the line

you
added? I'm definitely not up to speed on Tom's last suggeston:

gathering
the file list into an array...; could you by chance point me to a

relevant
example? THANKS AGAIN...!

"Tom Ogilvy" wrote in
:

I am not sure why you get a type mismatch, but you never change the
variable file in your loop, so it it is entered, it should loop
forever.


file = Dir() ' get the next filename



However, it isn't advisable to change your directory while doing a
loop based on Dir. This can cause problems. It is better to gather
your file list to an array in the Dir loop, then loop through the
array making your changes.








 
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



All times are GMT +1. The time now is 10:32 AM.

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

About Us

"It's about Microsoft Excel"