troubleshooting Question

VBA: Make an .xml UTF-8 (2 byte) file

Avatar of New_Alex
New_AlexFlag for Cyprus asked on
Microsoft OfficeMicrosoft ExcelVB Script
2 Comments1 Solution2159 ViewsLast Modified:
Function SaveTextToFile(FileFullPath As String, _
 sText As String, Optional Overwrite As Boolean = False) As _
 Boolean
    
On Error GoTo ErrorHandler
Dim iFileNumber As Integer
iFileNumber = FreeFile

If Overwrite Then
    Open FileFullPath For Output As #iFileNumber
Else
    Open FileFullPath For Append As #iFileNumber
End If

Print #iFileNumber, sText
SaveTextToFile = True

ErrorHandler:
Close #iFileNumber
End Function

The above function saves the String contained in the variable  sText in the File given in the variable FileFullPath.

My problem is that my String contains also characters in other languages and I want to save it in a file with the extension .xml so it opens in Excel.

In the attached .zip file there are 2 files. "book1.xml" and "book2.xml".
book1.xml can be opened in an XML editor
book2.xml has been made using the aforementioned function and can not be opened in an XML editor since there is an encoding error
 
book1.xml is correct UTF-8
book2.xml made using the aforementioned function is defnitely saved as a one byte encoded file, and hex C5 et al. are illegal UTF-8, I am not sure it is ANSI, but it is a single byte encoding

Is it possible to make some modifications so the above mentioned function saves the multi-language string as an .xml UTF-8 (2 byte) file so it is compatible with other languages and opens with Excel or .xml editors?

Thank you.

The-xml-files.zip
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros