Convert text file to true utf-8 (not utf-16 BE BOM)

MPW

Well-known Member
Joined
Oct 7, 2009
Messages
571
Office Version
  1. 365
Platform
  1. Windows
Hi, I have created an xml file that is based on data from Excel. However, the result is that it is in an ansi format. The program that uses this file requires the utf-8 format and I am currently able to emulate this by throwing it into Notepad++ to format it correctly. I would like to accomplish this automatically.

I best code I found in several places on the web was this:
VBA Code:
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set stream = CreateObject("ADODB.Stream")
        stream.Open
        stream.Type = 2
        stream.Charset = "utf-8"
        stream.LoadFromFile strPath
        fso.OpenTextFile(strPath, 2, True, True).Write stream.ReadText
        stream.Close
Unfortunately, this results in the "utf-16 BE BOM" instead of the desired "utf-8".
My question is "How can I modify the above code to get the right output or is there a better method?"

Thank you for the use of your brains.
 
I'll need to look into this further when I get a chance. If I have any other suggestions, I'll post back.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
No worries, thanks for the look. Both of you.
 
Upvote 0
Back from the holiday's, thought I would bump this since it remains unresolved.

It is the only missing piece of my project. Currently it still needs to be converted in Notepad++, but I am sure there is a better alternative.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top