Do While Problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following:

opath = InputBox("Enter path for current month data", cmpath)
If Right(opath, 1) <> "\" Then
opath = opath & "\"
End If
oname = Dir(opath & "*.xls")
Debug.Print opath
icount = 0
Do While oname <> ""
icount = icount + 1
Debug.Print icount, oname
If icount > 100 Then Exit Do
Loop

I have at least 10 xls workbooks in the folder, but it's only seeing the
first and not looping to the remainder. Any idea why?
 
Do While oName <> ""
icount = icount + 1
Debug.Print icount, oName
If icount > 100 Then Exit Do
oName = Dir
Loop



--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)
 
See if this idea helps. As written it makes a list of files
Sub anotherfindfiles()
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim MediaFileLocation As String
MediaFileLocation = "c:\YOURFOLDER\*.YOURFILEEXTENSION"
FN = Dir(MediaFileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub
 
All air code but try something like this.

Dim fso, f, f1, fc, s, icount
folderspec = InputBox("Enter path for current month data", cmpath)
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
icount = icount + 1
Debug.Print icount, f1
If icount > 100 Then Exit For
Next


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
|I have the following:
|
| opath = InputBox("Enter path for current month data", cmpath)
| If Right(opath, 1) <> "\" Then
| opath = opath & "\"
| End If
| oname = Dir(opath & "*.xls")
| Debug.Print opath
| icount = 0
| Do While oname <> ""
| icount = icount + 1
| Debug.Print icount, oname
| If icount > 100 Then Exit Do
| Loop
|
| I have at least 10 xls workbooks in the folder, but it's only seeing the
| first and not looping to the remainder. Any idea why?
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top