Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save as XML with VBA?

Tags:

xml

excel

vba

Is there any way to save an Excel table as XML? I have the XML Schema file... and some data in a table... and I have in Excel the Save as XML file option but can I save a file as XML from VBA? I want to automate a process and I didn;t find nothing on this option. Thanks!

like image 409
Andrei Ion Avatar asked Mar 04 '12 19:03

Andrei Ion


People also ask

How do you convert Excel to XML using VBA?

VBA code to Convert and Save the Excel to XML- Instructions Step 1: Open a New Excel workbook. Step 2: Press Alt+F11 – This will open the VBA Editor (alternatively, you can open it from Developer Tab in Excel Ribbon) Step 3: Insert a code module from then insert menu of the VBE.

What is XML in VBA?

Excel VBA XML. The full form of XML is eXtensible Markup Language which is much like an HTML file, is designed to store and transport the data from different programs. XML file stores the data which includes the splits and separators. We can create a VBA code by which we can import the data from the XML file into Excel ...

How do I create an XML file from Excel?

Click File > Save As, and select the location where you want to save the file. , point to the arrow next to Save As, and then click Other Formats. In the File name box, type a name for the XML data file. In the Save as type list, click XML Data, and click Save.


1 Answers

the good ol' macro recorder saved me this time :)) (Why didn't I used it before I posted here?) So... To load an xml schema you have:

ActiveWorkbook.XmlMaps.Add("Book2.xml", "raport").Name _
        = "raport_Map"

And to save it as xml:

ActiveWorkbook.SaveAsXMLData Filename:="Book3.xml", _
        Map:=ActiveWorkbook.XmlMaps("raport_Map")

Who would have thought that it's that easy?

like image 190
Andrei Ion Avatar answered Nov 10 '22 14:11

Andrei Ion