从vba的Unicode字符串到平面文件

Ami*_*mit 3 unicode vba flat-file

我想将一个unicode字符串存储在一个excel/vba宏的Windows框中的平面文件中.宏将普通字符串转换为unicode表示,需要将其存储在文件中并稍后检索.

Oor*_*ang 6

如上所述,您可以使用Microsoft Scripting Runtime(scrrun.dll).我在下面发布了一些例子.有些人还喜欢本机文件IO功能.这里有一个广泛的(相当全面的线程)线程:http://www.xtremevbtalk.com/showthread.php?t = 123814

但是对于Unicode文件,使用Textstreams可能是最不痛苦的:)

Public Sub StringToTextFile(ByVal path As String, ByVal value As String)
    'Requires reference to scrrun.dll
    Dim fso As Scripting.FileSystemObject
    Dim ts As Scripting.TextStream
    Set fso = New Scripting.FileSystemObject
    Set ts = fso.CreateTextFile(path, False, True)
    ts.Write value
    ts.Close
End Sub

Public Sub LazyMansWay(ByVal path As String, ByVal value As String)
    'Reference counting will cause the objects to be destroyed. The termination
    'events of the classes will cause the connections to be closed.
    CreateObject("Scripting.FileSystemObject").CreateTextFile(path, False, True).Write value
End Sub
Run Code Online (Sandbox Code Playgroud)