View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach[_6_] Otto Moehrbach[_6_] is offline
external usenet poster
 
Posts: 201
Default Loping through files in a folder

Tom
My code is the same as yours but mine didn't work last night. Now it
does, as does yours. Senility is a weird thing.
Now I have another question. I have folders New and History. I am
looping through the files in the New folder. For each file I want to ask
the question: "Is this file (same name) in the History folder?" The only
thing I know to do is to loop through all the files in the History folder
and compare file names. Is there a better way? Maybe Find? Thanks for
your help. It is very much appreciated. Otto
"Tom Ogilvy" wrote in message
...
Sub Tester9()
PathOnlysource = "C:\Data2"

ChDir PathOnlysource
TheFile = Dir(PathOnlysource & "\*.xls")
Do While TheFile < ""
Debug.Print TheFile
TheFile = Dir
Loop

End Sub

works fine for me. You want to look at the file, then do the TheFile =

Dir

--
Regards,
Tom Ogilvy


Otto Moehrbach wrote in message
...
Excel 2003
From my notes I have: (PathOnlySource is the full path to the folder

holding
the files)
ChDir PathOnlySource
TheFile = Dir(PathOnlySource & "\*.xls")
Do While TheFile < ""
TheFile = Dir
MsgBox TheFile
Loop

I thought that the line:
TheFile = Dir(PathOnlySource & "\*.xls")
would get the first .xls file name in the folder, which it appears to be
doing. And I thought that the line:
TheFile = Dir
Would get subsequent file names which it appears it doesn't do. Where

am
I
going wrong? Thanks for your help. Otto