利用FileSystemObject对象来读写文本文件。
新建一个标准EXE工程,引用 Microsoft Scripting Runtime。
窗口代码如下:
'用户昵称: 留下些什么
'个人简介: 一个会做软件的货代
'CSDN网址:https://blog.csdn.net/zezese
'电子邮箱:31319180@qq.com
Option Explicit
Private Sub Command1_Click()
'先引用 Microsoft Scripting Runtime
Dim fso As New FileSystemObject, ts As TextStream
Dim strTxtFile As String
strTxtFile = "c:\读写文本文件.txt"
'写
Set ts = fso.CreateTextFile(strTxtFile)
ts.Write Now & ":利用FileSystemObject对象来读写文本文件。"
ts.Close
'读
Set ts = fso.OpenTextFile(strTxtFile)
Debug.Print ts.ReadAll
ts.Close
End Sub