Advertisement

03.05.2008 at 09:38AM PST, ID: 23216807
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Making XML file using Excel macro

Asked by Frosty555 in VB Script, Extensible Markup Language (XML), Microsoft Excel Spreadsheet Software

Tags:

I'm making an XML file from some data in an excel spreadsheet. I'm using a VBA macro to do it. I basically build a big string called XMLFileText by tacking on the various values of different cells. I use the [CDATA ... ]] operator in XML so that I don't have to escape some the text, as you'll see in the code snippet.

Then I write it out to an XML file using FileSystemObject.TextStream.Write().

But my problem is that the excel file sometimes contains french characters, and that little << >> french style quote (I think it's called a "guillemets"), and other weird characters. When there are non-ascii characters in the string, The TextStream.Write() call fails with "Invalid Procedure Call Or Arguement".

I also know XML itself doesn't just handle unicode text. You need to excape it somehow, and I don't know if the [[CDATA ]] construct does it for me or not.

The code below isn't all my code, just an example. So can someone help me format the excel cells in a way that I can encode it into a standard ascii xml file using file system object?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
Dim ERsheet As Worksheet
    Set ERsheet = ActiveWorkbook.Worksheets("DATA")
 
    Dim XMLFileText as String
    XMLFileText = ""
    XMLFileText = XMLFileText & "<?xml version=""1.0"" encoding=""ISO8859-1"" ?>" & vbNewLine
    XMLFileText = XMLFileText & "<!DOCTYPE EXAM SYSTEM ""enhexam.dtd"">" & vbNewLine
    XMLFileText = XMLFileText & tabs(0) & UCase("<EXAM>") & vbNewLine
    ....
                             XMLFileText = XMLFileText & tabs(3) & UCase("<question><![CDATA[") & Trim(.Range(newcolname(2)).Value) & UCase("]]></question>") & vbNewLine
                            XMLFileText = XMLFileText & tabs(3) & UCase("<response1><![CDATA[") & Trim(.Range(newcolname(3)).Value) & UCase("]]></response1>") & vbNewLine
                            XMLFileText = XMLFileText & tabs(3) & UCase("<message1><![CDATA[") & Trim(.Range(newcolname(4)).Value) & UCase("]]></message1>") & vbNewLine
                            XMLFileText = XMLFileText & tabs(3) & UCase("<response2><![CDATA[") & Trim(.Range(newcolname(5)).Value) & UCase("]]></response2>") & vbNewLine
                            XMLFileText = XMLFileText & tabs(3) & UCase("<message2><![CDATA[") & Trim(.Range(newcolname(6)).Value) & UCase("]]></message2>") & vbNewLine
                            XMLFileText = XMLFileText & tabs(3) & UCase("<response3><![CDATA[") & Trim(.Range(newcolname(7)).Value) & UCase("]]></response3>") & vbNewLine
                            XMLFileText = XMLFileText & tabs(3) & UCase("<message3><![CDATA[") & Trim(.Range(newcolname(8)).Value) & UCase("]]></message3>") & vbNewLine
 
 
 
    If createfileflag = True Then
        Dim FSO As Object
        Dim newFile As Object
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set newFile = FSO.CreateTextFile(filepath)
        newFile.Write (XMLFileText)
        newFile.Close
        Set newFile = Nothing
        Set FSO = Nothing
   End If
[+][-]03.05.2008 at 10:10AM PST, ID: 21052812

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.05.2008 at 11:34AM PST, ID: 21053573

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.05.2008 at 11:35AM PST, ID: 21053583

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.05.2008 at 11:51AM PST, ID: 21053746

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.05.2008 at 10:33PM PST, ID: 21057875

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 06:19AM PST, ID: 21060335

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.06.2008 at 08:57PM PST, ID: 21067478

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: VB Script, Extensible Markup Language (XML), Microsoft Excel Spreadsheet Software
Tags: Microsoft Excel
Sign Up Now!
Solution Provided By: Frosty555
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628