VBS Excel 宏 VBA有时需要写出一些内容到文件,如何处理呢?


Dim filePath As String
filePath = "C:\temp\MyTestFile.txt"

' The advantage of correctly typing fso as FileSystemObject is to make autocompletion
' (Intellisense) work, which helps you avoid typos and lets you discover other useful
' methods of the FileSystemObject
Dim fso As FileSystemObject
Set fso = New FileSystemObject
Dim fileStream As TextStream

' Here the actual file is created and opened for write access
Set fileStream = fso.CreateTextFile(filePath)

' Write something to the file
fileStream.WriteLine "something"

' Close it, so it is not locked anymore


How to create and write to a txt file using VBA


与《VBS Excel 宏 VBA 写文件 示例代码》相关的博文:


Admin Avatar