您可能希望将数据写入纯文本文件。使用 FileSystemObject 的 CreateTextFile 方法。此处的文档:
http://msdn.microsoft.com/en-us/library/aa265018(v=vs.60).aspx
网上有很多关于如何迭代工作表、捕获数据然后使用 WriteLine 方法的示例。
Sub ExampleTextFile()
Dim fso as Object
Dim oFile as Object
Dim fullExport as String
'Script that will capture data from worksheet belongs here _
' use the fullExport string variable to hold this data, for now we will _
' just create a dummy string for illustration purposes
fullExport = "Example string contents that will be inserted in to my text file!"
Set fso = CreateObject("Scripting.FileSystemObject")
'In the next line, replace "C:\filename.txt" with the specified file you want to create
set oFile = fso.CreateTextFile("C:\filename.txt", Overwrite:=True, unicode:=True)
oFile.WriteLine(fullExport) '<-- inserts the captured string to your new TXT file
oFile.Close
Set fso = Nothing
Set oFile = Nothing
End Sub
如果您有字符编码问题(我最近遇到了 UTF16LE 与 UTF8 编码的问题,您将需要使用 ADODB.Stream 对象,但这将需要另一种写入文件的方法。