VBA code to convert excel to xml

Home/VBA/VBA code to convert excel to xml

We can use VBA to convert and Save the Excel File as XML file. This example macro will help us to know how to convert Excel Worksheet into a XML file format. This can be used in Excel 2003,2007,2010,2013.



50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates

vba code to convert excel to XML- Syntax

Here is the example Excel VBA Syntax to convert the Excel to XML format.

Workbook.SaveAs fileName:="filepath to save the csv file", FileFormat:=xlXMLSpreadsheet, ReadOnlyRecommended:=False, CreateBackup:=False

VBA code to Convert and Save the Excel to XML- Example

Here is the example macro to convert the Excel worksheet to XML file.

'vba code to convert excel to xml
Sub vba_code_to_convert_excel_to_xml()
Set wb = Workbooks.Open("C:\temp\testwb.xlsx")
wb.SaveAs fileName:="C:\temp\testX.xml", FileFormat:= _
xlXMLSpreadsheet, ReadOnlyRecommended:=False, CreateBackup:=False
End Sub

This macro will open an existing Excel workbook from the C drive and Convert the file into XML and Save the file with .xml extension in the specified Folder. We are using Workbook Open method to open a file. SaveAs method to Save the file into destination folder. This example will be help full, if you wan to convert all excel files in a directory into XML (xlXMLSpreadsheet format) file.

VBA code to Convert and Save the Excel to XML- Instructions

Please follow the below step by step instructions to test this Example VBA Macro codes:

  • 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
  • Step 4: Copy the above code and paste in the code module which have inserted in the above step
  • Step 5: Change the Workbook name in the code as per your example folder and also change the destination file path as per your requirement
  • Step 6: Now press F5 to execute the code or F8 to debug the Macro to check the macro
By |January 20th, 2015|VBA|0 Comments

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

Leave A Comment

Related pages

deleting duplicate rowsvba create macromicrosoft excel nested ifresource capacity planning template excelvba excel charthow to learn vlookupvba controlrecording macros in excel 2010spider web chart excelunique records excelexcel msgboxhow to convert xml to excel 2007excel formula in vba codehow to consolidate excel filesrange select vbaproject management excel trackerms excel substitutehow to edit protected excel filevba variable arrayexcel getopenfilenamevba excel redim preservevba upper caseunmerging cells in excelmacro in excel 2007 tutorialexplain vlookup in excellearn vba for accessexample of vlookup function in excelexcel functions vlookupexcel vba if statementexcell concatenatehow to highlight duplicates in excel 2003insert a row in excelexcel vba macros tutorialvba excel ebookhow to hide a row in excelexcel vba timevaluemicrosoft excel gantt chart templatevba excel instrfileformat vbaexcel task tracker templateexcel adois there a way to delete duplicates in excelvba and macroseliminating duplicate rows in excelpivot table in sql server 2008 exampleconnect excel to oracle databasevba trim spacesdisable excel macroselseif excelcolor code vbahyperlink function in excelworksheetfunction sumexcel macro inputboxcolumn addition worksheetvba lookupexcel vba insert multiple rowsexcel kpi dashboard examplesdim vba excelhow to concatenate in excel vbahow to create command button in excelhow to pivot table excel 2010free dashboard templates powerpointvba function tutorialload userformworking with macros in excelsaving macros in excelcreating pivot table in excel 2013excel macro to delete blank rowssql frequently asked interview questions and answersms sql interview questions and answers pdfexcel vba programming for dummiesexcel formulas lookuppivot table excel tutorial 2010workbooks closeadvanced excel shortcut keysdraw charts in excel