How to create unicode files using VBA?
Using the Scripting Runtime library you can create a unicode text file and write to it like:
Sub test()
'set reference to Microsoft Scripting Runtime lib
Dim strFile As String, strRange1 As String, strRange2 As String
Dim fso As FileSystemObject
Dim txtStrm As TextStream
strFile = "Y:\Work\MyFile.htm" 'amend as appropriate
strRange1 = Range("A1").Value
strRange2 = Range("A2").Value
Set fso = New FileSystemObject
Set txtStrm = fso.CreateTextFile(strFile, Overwrite:=True, Unicode:=True)
With txtStrm
.WriteLine strRange1
.WriteLine strRange2
.Close
End With
End Sub
You must set a reference within the VBE via Tools>References to the Microsoft Scripting Runtime lib.
Comments