View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Loping through files in a folder

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