This isn't something I've used in the 'real world', but from my reading of
the article at the URL below, I believe it should be possible to do this
using the ADO Stream object.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmt
hreadvbx.asp
I tested using the following code. It runs without error. But I'm not sure
how to determine that the resulting file is, in fact, a UTF-8 file. (I know
it can be done by examining the file using a HEX editor, but I don't
currently have one installed).
Public Sub SaveStream()
Dim objStream As Stream
Set objStream = New Stream
objStream.Open
objStream.Position = 0
objStream.Charset = "UTF-8"
objStream.WriteText "A string of text"
objStream.SaveToFile "c:\dsdata\mightbeutf8.txt", adSaveCreateOverWrite
objStream.Close
End Sub

Signature
Brendan Reynolds (MVP)
> Hello, i'm trying to change the encoding of a text file from unicode to
> UTF8
[quoted text clipped - 3 lines]
> days
> on the net but couldn't find the answer. Please help...
Brendan Reynolds - 24 Sep 2005 13:24 GMT
Figured out a way to test it. Use the code to write an XML file including
the encoding attribute, and open the XML file in Internet Explorer. Internet
Explorer will complain if the encoding of the XML file doesn't match the
encoding attribute, so if Internet Explorer doesn't complain (and it
doesn't) it worked! :-)
Public Sub SaveStream()
Dim objStream As Stream
Dim strXML As String
strXML = "<?xml version='1.0' encoding='UTF-8'?> " & _
"<dataroot>" & _
"<tblTest>" & _
"<TestID>1</TestID>" & _
"</tblTest>" & _
"</dataroot>"
Set objStream = New Stream
objStream.Open
objStream.Position = 0
objStream.Charset = "UTF-8"
objStream.WriteText strXML
objStream.SaveToFile "c:\dsdata\mightbeutf8.xml", adSaveCreateOverWrite
objStream.Close
End Sub
Just for laughs (or more seriously, to demonstrate that Internet Explorer
really would complain if the result wasn't a UTF-8 file) try changing the
encoding attribute to 'UTF-16' without also changing the objStream.Charset,
run the code again, and see what happens when you try to open the XML file
in Internet Explorer.

Signature
Brendan Reynolds (MVP)
> This isn't something I've used in the 'real world', but from my reading of
> the article at the URL below, I believe it should be possible to do this
[quoted text clipped - 28 lines]
>> days
>> on the net but couldn't find the answer. Please help...