Consulting

Results 1 to 3 of 3

Thread: Cannot open all files in folder, file name problem, VBA help please!

  1. #1

    Cannot open all files in folder, file name problem, VBA help please!

    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


    [VBA]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[/VBA]

  2. #2
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    [vba]Open "C:\Documents and Settings\SchroP96\Desktop\DPS Data (Summer and Fall2010)\10-06-2010\continuously2\" & _
    File For Input As #1
    [/vba]

  3. #3
    Awesome, thanks a lot man, the really helped!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •