如何从VBA将UTF-8编码的字符串写入文本文件,例如

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

当然不是我所期望的...

关于vba - 保存用VBA编码的文本文件UTF-8,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2524703/

10-10 04:32