Read an already opened CSV file line by line

  • Hello all,

    I created a vba program last year to read a csv file line by line. Below is basically how I coded it (not my actual code).

    Dim fileName As String, textData As String, textRow As String, fileNo As Integer
    fileName = "C:\text.csv"
    fileNo = FreeFile 'Get first free file number  
    Open fileName For Input As #fileNo
    Do While Not EOF(fileNo)
       Line Input #fileNo, textRow
       textData = textData & textRow
    Close #fileNo

    The code above works perfectly fine when I use it to open a csv and the read it.

    What I want to do instead is read an already opened csv file using the freefile method above (or whatever method there is to read an already opened csv file line by line).

    Yes, I know it's an odd request, but I'm trying to alter as little of the original code as possible. I could definitely make it work some other way, but it would require rewriting almost all of it and I don't have enough time to do so.

    For those interested in more information, the program navigates to a website and opens a csv. I could have it download the csv and then use the code above, but I'm trying to make the program run without any user input (like asking where to save something).

    Thank you!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!