+ Reply to Thread
Results 1 to 4 of 4

File encoding problem

  1. #1
    Registered User
    Join Date
    09-05-2005
    Posts
    3

    Smile File encoding problem

    Hi,

    My purpose is create a macro that writes a XML file.

    I have created a file text with several Print #, string commands.
    In fact, it is a text file with .xml extension, and I have put in the first line the tag <?xml version='1.0' encoding='UTF-8' ?>, because I want this document to be encoded that way.

    What happens is that I think that the way I create the file doesn't use the UTF8 encoding, so when I try to open the XML file with Internet Explorer I get an error (I use some special characters, as &iacute because there are problems with some characters.

    I would like to know how to create a file with UTF-8 encoding, or the other option would be how to change the encoding of an existing file (even better!). In both cases, I need to do all these thing via an excel macro (vba).

    I have spent several days surfing the web and I'm beginnig to desperate!!!!

    Thanks in advance

  2. #2
    Nick Hebb
    Guest

    Re: File encoding problem

    The following method should work:

    Dim fso As FileSystemObject
    Dim ts As TextStream

    Set fso = New FileSystemObject
    Set ts = fso.CreateTextFile("C:\myFile.xml")

    ts.WriteLine "<? xml version = " & Chr(34) & "1.0" & Chr(34) & _
    " encoding = " & Chr(34) & "UTF-8" & Chr(34) & " ?>"

    ' Use the ts (TextStream object) to write the remaing stuff here

    ts.Close
    Set ts = Nothing
    Set fso = Nothing

    Using the TextStream instead of Print should fix the encoding. Also,
    the Chr(34)'s are quotes. You can do this or double quotes, but I find
    the double quotes hard to read.


    ----
    Nick Hebb
    BreezeTree Software
    http://www.breezetree.com


  3. #3
    Registered User
    Join Date
    09-05-2005
    Posts
    3

    Arrow

    Thanks for your response.

    I have replaced the print statements with the Windows Scripting Runtime commands (FileSystemObject ,writeline, etc) that you suggested.

    Unfortunately, I still have the same problem (I have attached the zipped xml file that causes my nightmares, just in case it would be useful for any suggestion...)

    At this point, I'm starting to think that maybe the reason of the problem is not what I supose it was ...

    Thanks in advance!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    09-05-2005
    Posts
    3

    Unhappy

    Please I need help about subject shown above.

    Thanks in advance to all of u!!!

    Ani.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1