本文介绍了如何将Unicode字符保存到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在Word的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?

推荐答案

我希望这将适合VBA for Word在Mac上,但在Windows上我有FileSystemObject的CreateTextFile方法(参见)。我可以定义创建一个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字符保存到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 21:12