保存用 VBA 编码的 UTF-8 文本文件 [英] Save text file UTF-8 encoded with VBA
本文介绍了保存用 VBA 编码的 UTF-8 文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 UTF-8 编码的字符串从 vba 写入文本文件,例如
how can I write UTF-8 encoded strings to a textfile from vba, like
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
是否有应用程序级别的设置?
Is there some setting on Application level?
推荐答案
我在 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
当然不像我预期的那样......
Certainly not as I expected...
这篇关于保存用 VBA 编码的 UTF-8 文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文