保存使用VBA编码的文本文件UTF-8

如何将UTF-8编码的字符串写入到vba的文本文件,如

Dim fnum As Integer
fnum = FreeFile
Open "myfile.txt" For Output As fnum
Print #fnum, "special characters: äöüß" 'latin-1 or something by default
Close fnum

在应用程序级别有一些设置?

我发现web的答案:

Dim fsT As Object
Set fsT = CreateObject("ADODB.Stream")
fsT.Type = 2 'Specify stream type - we want To save text/string data.
fsT.Charset = "utf-8" 'Specify charset For the source text data.
fsT.Open 'Open the stream And write binary data To the object
fsT.WriteText "special characters: äöüß"
fsT.SaveToFile sFileName, 2 'Save binary data To disk

当然不是我预期的…

http://stackoverflow.com/questions/2524703/save-text-file-utf-8-encoded-with-vba

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:保存使用VBA编码的文本文件UTF-8