VBA Code to Convert XML to Excel: 2 Methods

Method 1 – Go to VBA Module

In this step, we will show how to get into the VBA module.

  • Enter a blank Excel sheet.
  • Go to the Sheet Name section at the bottom section.
  • Press the right button of the mouse.
  • Choose View Code from the appeared Context Menu.

Introduce VBA Module to convert file from XML to Excel

  • VBA window appears now.
  • Click on the Insert tab.
  • Choose the Module option from there.

  • The VBA module window appears to write code.


Method 2 – Write VBA Code in the Module and Run

  • Copy and paste the following VBA code on the module.
Sub Conversion()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim w_book As Workbook
With Workbooks.OpenXML("D:\OneDrive\Softeko\25-0180_5352\Salary_Sheet.xml" _
, , xlXmlLoadImportToList)
.SaveAs ("D:\OneDrive\Softeko\25-0180_5352\Salary_Sheet.xlsx")
.Close
End With
End Sub

Apply VBA Code to convert from XML to Excel

  • Press the F5 button to run the code.

Check the Converted File

We will check the newly created file after successfully implementing the VBA code.

  • Open the folder from File Explorer.

Check Converted Excel File from XML using VBA code

We can see that the Excel file is saved here successfully.

  • Open the Excel file.

Data were also extracted here properly.


Download Practice Workbook

You can download the following practice workbook to exercise while you are reading this article.


Related Articles

<< Go Back to Import XML to Excel | Importing Data in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Alok Paul
Alok Paul

Alok Paul has completed his B.Sc. in Electronics and Telecommunication Engineering from East West University. He has been working on the ExcelDemy project for more than 2 years. He has written 220+ articles and replied to numerous comments. He is experienced in Microsoft Office, especially in Excel. He also led some teams on Excel and VBA content development. He has a keen interest in Advanced Excel, Data analysis, Excel Pivot Table, Charts, and Dashboard. He loves to research... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo