Macro or VBA to import specific data from xml file

fcfcadd

New Member
Joined
Aug 17, 2020
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
I have several xml files that I would like to be able to import specific data from into an excel workbook and I am not sure where to start to get this to automated instead of dragging and dropping each time from the XML Source area. The image attached is just the first portion of the xml file. What I am trying to do is extract very specific lines of that data only to be imported into excel. The lines of data will be the same all the time for each xml file I am trying to import.
 

Attachments

  • Screen Shot 08-17-20 at 11.36 AM.PNG
    Screen Shot 08-17-20 at 11.36 AM.PNG
    67.6 KB · Views: 364

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Welcome to MrExcel forums.

This can be done with a VBA macro which uses the MS XML class library, for example as a starting point:


Change the .Load line to your local file: .Load "C:\path\to\your file.xml"

And the For Next loop would need changing for your specific data. The macro requires a reference to Microsoft XML, v6.0, set via Tools -> References in the VBA editor.
 
Upvote 0
John,

I get an error when trying to run that sample code
 
Upvote 0
You may need to change these lines:
VBA Code:
    Dim objDOMDocument As DOMDocument
    Set objDOMDocument = New DOMDocument
to:
VBA Code:
    Dim objDOMDocument As DOMDocument60
    Set objDOMDocument = New DOMDocument60

Post your code if you still get errors and tell us the exact error and on which line it occurs.

Remember, the example link is for that specific question and the code for your data will need extensive changes. The example was just to show the basic idea, with SelectNodes and SelectSingleNode.
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,559
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top