Link to home
Get AccessLog in
Avatar of Peter Chan
Peter ChanFlag for Hong Kong

asked on

Problem to open file

Hi,
I get this problem
User generated imagedue to last 2nd line below
    If Dir(File0) = "" Then
        Set f = fs.createtextfile(File0)
    Else
        Set f = fs.OpenTextFile(File0, 3, TristateFalse)
    End If

Open in new window

Why?
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of Peter Chan

ASKER

Many thanks.
I want to further read all the lines, from the text file. Any example?
Oh, numerous - just bing/google on that.

/gustav
Using these

    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    File0 = ActiveWorkbook.Path & "\MonthStatus.txt"
    
    Dim iFile As Integer: iFile = FreeFile
    Open File0 For Input As #iFile
    Do Until EOF(1)
        Line Input #1, TextLine
        
        MsgBox TextLine
        If Trim(TextLine) <> "" Then
            ...
        End If
    Loop

Open in new window

I cannot read the lines inside the file. Why?
A little more precision is needed:
    Dim fs, File0, TextLine
    Set fs = CreateObject("Scripting.FileSystemObject")
    File0 = ActiveWorkbook.Path & "\MonthStatus.txt"
    
    Dim iFile As Integer: iFile = FreeFile
    Open File0 For Input As #iFile
    Do Until EOF(iFile)
        Line Input #iFile, TextLine
        
        MsgBox TextLine
        If Trim(TextLine) <> "" Then
        '    ...
        End If
    Loop

Open in new window

/gustav
Grade B? What was missing, please?

/gustav
Grade B? What was missing, please?

Again! The answer is NOT the problem!