View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Brent Brent is offline
external usenet poster
 
Posts: 109
Default readall gives error for last file from getfolder().files

Cannot figure out why this happens only on the lsat file found by the
getfolders().files. Any help would be great!!

Set apps = fso.getfolder("c:\ds_wind").Files
Do
Set apps = fso.getfolder("c:\ds_wind").Files
Loop While apps.Count < (Range("d1") - Date + 3)
For Each Filename In apps
Set fs = fso.opentextfile(Filename)
txtstring = ""
txtstring = fs.readall
fs.close
txtstring = Right(txtstring, Len(txtstring) - InStr(txtstring, "R:") - 18)
txtstring = Left(txtstring, InStr(txtstring, "TOTAL:") - 1)
txtarray = Split(txtstring, " ")
txtarray2 = ""
For i = 0 To UBound(txtarray)
txtarray(i) = Trim(txtarray(i))
txtarray(i) = Replace(txtarray(i), Chr(10), "", 1, -1,
vbBinaryCompare)
txtarray(i) = Replace(txtarray(i), Chr(13), "", 1, -1,
vbBinaryCompare)
If txtarray(i) < "" And txtarray(i) < "." Then
txtarray2 = txtarray2 + "," + txtarray(i)
End If
Next
txtarray = Split(txtarray2, ",")
filedate = "" & txtarray(1) & ""
i = 9
If Range("a5").Value = "" Then
rwidx = 5
Else
rwidx = Range("a4").End(xlDown).Row + 1
End If
While i < UBound(txtarray)
Cells(rwidx, 1) = "'" & filedate
Cells(rwidx, 2) = "'" & txtarray(i)
Cells(rwidx, 3) = "'" & txtarray(i + 5)
Cells(rwidx, 4) = "'" & txtarray(i + 6)
Cells(rwidx, 5) = "'" & txtarray(i + 9)
i = i + 10
rwidx = rwidx + 1
Wend
Next