我想将 excel/vba 宏中的 unicode 字符串存储在 Windows 盒子上的平面文件中。该宏将普通字符串转换为 unicode 表示形式,需要将其存储在文件中并稍后检索。
如前所述,您可以使用 Microsoft 脚本运行时 (scrrun.dll)。我在下面发布了一些示例。有些人还喜欢本机文件 IO 功能。这里有一个广泛的(并且相当全面的线程)线程:http://www.xtremevbtalk.com/showthread.php?t=123814
然而,对于 Unicode 文件,使用 Textstream 可能是最不痛苦的:)
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)