如何将 Unicode 字符保存到文本文件 [英] How to save a Unicode character to a text file
问题描述
这是在 Word for MAC VBA 中.我想将 Unicode 字符从文本框中保存到文本文件.例如这个字符⅛".
This is in Word for MAC VBA. I want to save the Unicode character from a text box to text file. For example this character "⅛".
我使用此代码.
Dim N as Long
N = FreeFile
Dim strText as String
strText = Textbox1.Text 'This is what is in the textbox "⅛"
Open <file path> For Output As N
Print #N, strText
Close N
它不保存 Unicode 字符.我知道我必须更改文本编码格式.我该怎么做?
It does not save the Unicode character. I understand I have to change the text encoding format. How do I do that?
同样的,如何读取Unicode格式的文本文件?
Likewise, how to read the text file with the Unicode format?
推荐答案
我希望这也适用于 Mac 上的 VBA for Word,但在 Windows 上我有 FileSystemObject 的 CreateTextFile 方法(请参阅 MSDN 文档).在那里我可以定义创建一个 unicode 文本文件.
I hope this will fit VBA for Word on Mac as well, but on Windows I have the CreateTextFile method of the FileSystemObject (see MSDN doc). There I can define to create a unicode text file.
Set fsObject = CreateObject("Scripting.FileSystemObject")
Set xmlFile = fsObject.CreateTextFile("path/filename.txt", True, True) 'the second "true" forces a unicode file.
xmlFile.write "YourUnicodeTextHere"
xmlFile.close
这篇关于如何将 Unicode 字符保存到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!