0

I am processing an XML in Excel, and I want to export the final value to a file. The XML is in a cell, and I am writing it using Open and Write of VBA. While doing so, I get the XML from the Cell all within one pair of quotes. The values of tag attributes (which are in quotes) get escaped with another quote.

Below is how it looks in the Cell.

<tag attr="value"/><tag>

And this is how it gets exported to file.

"<tag attr=""value""/><tag>"

I am using

 Open myFilePath For Output as #1
 Write #1, WorkSheets("Sheet1").Cells(1,2).Value
 Close #1
braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

If you want the output to file to appear exactly as it is in the cell, then use PRINT instead of WRITE.

Open myFilePath For Output as #1
  Print #1, WorkSheets("Sheet1").Cells(1,2).Value
Close #1

Output:

<tag attr="value"/><tag>

If you still need the quotes to encapsulate each string, then add them to the output:

  Print #1, Chr(34) & WorkSheets("Sheet1").Cells(1,2).Value & Chr(34)

Output:

"<tag attr="value"/><tag>"

.. though that may (will) confuse any parser that is attempting to read the file later.

CLR
  • 11,284
  • 1
  • 11
  • 29