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

标签 vba utf-8

如何从 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/

相关文章:

excel - 在 2019 年 8 月 Windows 更新之前将对象数组发送到变体可以正常工作,但更新后会失败

list - 更新数据验证列表范围

java - JAVA 中具有 2 个以上字节的 UTF8 字符串的 Substring 或 characterAt 方法

python - 如何将位串转换为 utf-8 字符串?

VBA AutoFilter 隐藏所有行 - 包括匹配条件的行

excel - 用于获取列中每个唯一值的范围的宏

vba - 在 UserForm 属性中使用 Dictionary.Exists 会给出错误 404 object required

python - 如何打开包含 utf-8 非编码字符的文件?

python - 匹配所有 utf-8/unicode 小写字母形式的正确正则表达式是什么

c++ - 此 UTF-8 实现是实现定义的还是定义明确的?