3

我在 excel 中创建一个宏来处理电子表格并将内容(文本)写入文件。我需要将此文件编码为 UTF-8。我尝试使用 OpenTextFile(... TristateTrue) 和 StrConv(.. vbUnicode) 将文件作为 unicode 打开,但这些仅将其转换为 UTF-16。我在网上到处搜索,找不到任何东西。这甚至可能吗?

谢谢

4

1 回答 1

2
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 编码的 UTF-8 文本文件

于 2015-02-23T04:22:16.977 回答