FrankSharp
FrankSharp

Reputation: 2632

Loop in VBA for get values in cells in Excel

The user select a path for a file and click yes, each path file are inserted in a worksheet(Column1).

I try to make a loop to read this path file in the worksheet(Column1) until the end of records

This is the code I try but do not work well because when the path is ="" I get an error. So I want to quit the when the file path is =""(cell = "")

    Do Until Workbooks(1).Worksheets(3).Cells(cnt, 1).Value = Null

    fileName = Workbooks(1).Worksheets(3).Cells(cnt, 1).Value


    Set oFS = oFSO.OpenTextFile(fileName) //If fileName="" I get error

    Do Until oFS.AtEndOfStream
        sText = sText & oFS.ReadLine
    Loop
    Debug.Print sText
    cnt = cnt + 1

RE6 sText, fileName

Loop

Thanks Frank

Upvotes: 0

Views: 1933

Answers (1)

Trevor Tippins
Trevor Tippins

Reputation: 2847

Why not just check for Trim$(Cell.Value) = "", rather than Null, on the first line?

Upvotes: 1

Related Questions