gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 01:35:18 27 4
gpt4 key购买 nike

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

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com