trying to store text file rows in VBA

前端 未结 2 1341
别那么骄傲
别那么骄傲 2020-12-04 01:08

Greetings, I\'m hoping for help in figuring out how to store each row of a text file read into a VBA program as a string. I want to modify one of the strings and then put t

2条回答
  •  盖世英雄少女心
    2020-12-04 01:45

    Look into the FileSystemObject (ref: 1, 2, 3)

    You have to go to menu and include the Microsoft Scripting Runtime and create a global variable Global fso as New FileSystemObject. Now anywhere in your code do things like fso.OpenTextFile() which returns a TextStream. Each TextStream has methods loke ReadLine(), ReadAll(), SkipLine(), WriteLine(), etc ...

    VBA References

    Here is a quick sample code.

    Sub TEST()
        Dim ts As TextStream
        Set ts = fso.OpenTextFile("text_file.txt", ForReading, False)
        Dim s As String
        s = ts.ReadAll()
    End Sub
    

提交回复
热议问题