reading entire text file using vba

前端 未结 8 1266
暗喜
暗喜 2020-12-06 11:03

I\'m trying to read a text file using vba. I tried the below code

Open \"C:\\tester.txt\" For Input As #1
Worksheets(\"UI\").Range(\"H12\").Value = Input$(LO         


        
相关标签:
8条回答
  • 2020-12-06 11:27

    The following code will loop through each line in the text document and print these from range H12 and downward in the UI-sheet.

    Sub ImportFromText()
        Open "C:\tester.txt" For Input As #1
        r = 0
        Do Until EOF(1)
            Line Input #1, Data
            Worksheets("UI").Range("H12").Offset(r, 0) = Data
            r = r + 1
        Loop
        Close #1
    End Sub
    
    0 讨论(0)
  • 2020-12-06 11:29

    I think an easier alternative is Data > From Text and you can specify how often the data is refreshed in the Properties.

    0 讨论(0)
提交回复
热议问题