Klaus
Wed Sep 26 17:42:34 CDT 2007
You could also add a "byte order mark", so Word and other apps can determine
it's a Unicode text file automatically:
' Convert String data to Unicode bytes.
uData = ChrW(&HFEFF) & Data
Regards,
Klaus
"Karl E. Peterson" <karl@mvps.org> wrote:
> slachevsky@gmail.com wrote:
>> I Have a Ansi txt File
>> I need to save it as a Unicode File into a Script using and Ole Object
>> I Can open it, modify it and save it but i don't know how to change
>> the encoding
>
> VB(A) Strings are Unicode naturally. If Word's object model doesn't
> provide a direct SaveAs in this format, just write the file directly using
> binary i/o...
>
> Public Function WriteFileU(ByVal FileName As String, ByVal Data As
> String) As Boolean
> Dim hFile As Long
> Dim uData() As Byte
>
> ' Convert String data to Unicode bytes.
> uData = Data
>
> ' Since this is binary, we need to delete existing crud.
> On Error Resume Next
> Kill FileName
>
> ' Okay, now we just spit out what was given.
> On Error GoTo Hell
> hFile = FreeFile
> Open FileName For Binary As #hFile
> Put #hFile, , uData
> Close #hFile
> Hell:
> WriteFileU = Not CBool(Err.Number)
> End Function
>
> --
> .NET: It's About Trust!
>
http://vfred.mvps.org
>