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
Thanks

Re: Ansi to Unicode Saveas by Russ

Russ
Mon Sep 17 13:15:20 CDT 2007

In my MacWord 2004 there is an option to (Save As) save a file as unicode
text (UTF- 16).
Also have you tried Google for conversion ideas?
<http://www.google.com/search?&q=convert+ansi+unicode>
<http://www.google.com/search?&q=convert+ansi+unicode+%2Bms+%2Bword>
<http://groups.google.com/groups?&q=convert+ansi+unicode+ingroup:word>

> 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
> Thanks
>

--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID


Re: Ansi to Unicode Saveas by Karl

Karl
Tue Sep 18 15:00:55 CDT 2007

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



Re: Ansi to Unicode Saveas by Klaus

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
>



Re: Ansi to Unicode Saveas by Karl

Karl
Thu Sep 27 17:27:28 CDT 2007

Klaus Linke <info@fotosatz-kaufmann.de> wrote:
> You could also add a "byte order mark", so Word and other apps can determine
> it's a Unicode text file automatically:

Good suggestion! I modified that library routine to this:

Public Function WriteFileU(ByVal FileName As String, ByVal Data As String,
Optional ByVal ByteOrderMark As Boolean = True) As Boolean
Dim hFile As Long
Dim uData() As Byte

' 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
If ByteOrderMark Then
' Indicate to other apps that this is Unicode text.
' http://en.wikipedia.org/wiki/Byte_Order_Mark
uData = ChrW$(&HFEFF)
Put #hFile, , uData
End If
' Convert String data to Unicode bytes.
uData = Data
Put #hFile, , uData
Close #hFile
Hell:
WriteFileU = Not CBool(Err.Number)
End Function

Thanks... Karl
--
.NET: It's About Trust!
http://vfred.mvps.org