保存用VBA编码的文本文件UTF-8 [英] Save text file UTF-8 encoded with VBA

查看:942
本文介绍了保存用VBA编码的文本文件UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆