Friday, November 29, 2019

 

Option Explicit






Sub read_file()

    Dim path As String, textline As String, text As String
    path = "C:\Users\NinhLD\Downloads\vba\cmp\excel_VBA.txt"
    
    Open path For Input As #1
        Do Until EOF(1)
            Line Input #1, textline
            Debug.Print textline
        Loop
    Close #1
End Sub



Sub write_file()


    Dim path As String
    path = Application.DefaultFilePath & "\testwrite.txt"
    
'    'write from begin
    Open path For Output As #1
        Write #1, "abc"
        Write #1, "ade"
        Write #1, "ghi"
    Close #1
    
    'write append to the end
    Open path For Append As #1
        Write #1, "123"
        Write #1, "456"
        Write #1, "789"
    Close #1
    
End Sub

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Lập trình hệ thống nhúng Linux . Powered by Luong Duy Ninh -