贴点代码作参考:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\a.txt", ForAppending, True)
f.writeline "嗨,你好!"
'or f.write "嗨,你好!"
f.Close
Dim MyChar
Open App.Path & "\a.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
MyChar = Input(1, #1) ' 读入一个字符。
Debug.Print MyChar ' 显示到立即窗口。
Loop
Close #1 ' 关闭文件。
Dim TextLine
Open App.Path & "\a.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
Debug.Print TextLine ' 在立即窗口中显示数据。
Loop
Close #1 ' 关闭文件。