尝试在VBA中存储文本文件行 [英] trying to store text file rows in VBA
问题描述
查看FileSystemObject(ref: 1 , 2 , 3 )
您必须转到菜单并包含 Microsoft Scripting Runtime
并创建一个全局变量 Global fso as New FileSystemObject
。现在,您的代码中的任何地方都可以执行 fso.OpenTextFile()
,返回一个 TextStream
。每个TextStream都有方法loke ReadLine()
, ReadAll()
, SkipLine() code>,
WriteLine()
等...
以下是一个快速示例代码。
Sub TEST()
Dim ts As TextStream
设置ts = fso.OpenTextFile(text_file.txt,ForReading,False)
Dim s As String
s = ts.ReadAll()
End Sub
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 them all back together, but do not know how to read through a text file and store each row as a separate variable in an intelligent way. Thanks for any help you can provide!
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 ...
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
这篇关于尝试在VBA中存储文本文件行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!