PDA

View Full Version : Cannot open all files in folder, file name problem, VBA help please!



pablo4429
10-18-2010, 06:40 PM
Hey all,
First of all thanks for the help. What I am trying to do is open each file in a folder one at a time, get some data, write it to some cells, then close the file for each file in the folder. I keep getting PathFile access errors and cannot seem to get it to go past the the *** line without VBA kicking it back. I have tried everything from "file.dps" to "*.dps" and almost anything else. By the way, .dps is a file extension for a proprietary program that generates the data. Any help you all could offer would really be great, I am at a loss.
Thanks,
Paul


Dim spath As String
Dim file As String
spath = "C:\Documents and Settings\SchroP96\Desktop\DPS Data (Summer and Fall2010)\10-06-2010\continuously2\"
ChDir spath
file = Dir("*.dps")
Do While file <> ""
***Open "C:\Documents and Settings\SchroP96\Desktop\DPS Data (Summer and Fall2010)\10-06-2010\continuously2" For Input As #1

Do While Not EOF(1)
linenum = linenum + 1
Line Input #1, textline
If linenum = 9 Then
textline1 = Mid(textline, 3)
Worksheets("Sheet1").Range("a1").Offset(k, 0) = textline1
End If
textline2 = Mid(textline, 4, 2)
Worksheets("Sheet1").Range("a5").Offset(k, 1) = textline2
If textline2 = 90 Then
textline2a = Mid(textline, 10, 7)
Worksheets("Sheet1").Range("a1").Offset(k, 1) = textline2a
k = k + 1
End If
Loop

Close #1
file = Dir
Loop

Tinbendr
10-18-2010, 07:00 PM
Open "C:\Documents and Settings\SchroP96\Desktop\DPS Data (Summer and Fall2010)\10-06-2010\continuously2\" & _
File For Input As #1

pablo4429
10-20-2010, 03:56 PM
Awesome, thanks a lot man, the really helped!