VBA EXCEL新建的TXT文件如何保存 编码为:Unicode
Sub CreateAfile
Dim fso,MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("C:\111.tmx",True,True)
MyFile.WriteLine("这只是个测试")
MyFile.Close
End Sub
call CreateAfile
Set Stream = CreateObject("adodb.stream")
- ‘定义常量
- Const adTypeBinary = 1
- Const adTypeText = 2
- Const adSaveCreateNotExist = 1
- Const adSaveCreateOverWrite = 2
- Stream.Open ’打开文件流
- Stream.Type = adTypeText '设置写入方式为TEXT
- Stream.Charset = "Unicode" ‘设置编码格式
- Stream.writetext textStr '将 textStr 写入文件流
- Stream.flush '更新文件流?
- Stream.savetofile FileName, adSaveCreateOverWrite ’将文件流写入文件 FileName
- Stream.Close ‘关闭文件流
- Set Stream = Nothing