Import xml intro excel

fabesmoros

New Member
Joined
Sep 26, 2014
Messages
3
I am importing an xml file into excel using VBA code. I am able to import the complete file but I would like to only import certain information.

The code I have to import the whole xml:
Sub ImportXMLtoList()
Dim strTargetFile As String
Application.DisplayAlerts = False
strTargetFile = "C:\Users\adrros\Desktop\Practice\TranD.xml"
Workbooks.OpenXML Filename:=strTargetFile, LoadOption:=xlXmlLoadImportToList
Application.DisplayAlerts = True
End Sub

This is an example of the mapping of the xml:
<Requests>
<Request="ABC" ReferenceNumber="1234" Date="2014-09-22" ID="123456789">
<BillTo>
<FirstName>JOHN</FirstName>
<LastName>SMITH</LastName>
<Address1>123 JOHN STREET</Address1>
<City>NEW YORK</City>
<State>NY</State>
<Zip>35421</Zip>
<Email>JOHNSMITH@HOTMAIL.com</Email>
<Country>US</Country>
<Phone>3056965225</Phone>
<IPAddress>111.111.111.1</IPAddress>
</BillTo>
<ShipTo>
<FirstName>JOHN</FirstName>
<LastName>SMITH</LastName>
<Address1>123 JOHN STREET</Address1>
<City>NEW YORK</City>
<State>NY</State>
<Zip>35421</Zip>
<Country>US</Country>
</ShipTo>
<Shipping>
<Method>TWO DAY</Method>
<Carrier/>
</Shipping>

I would only like to import the ReferenceNumber and the ID
The complete <Bill To> information
And the Zip Code and State from the Shipping information.

Thanks for your help
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
< Requests > -< Request Source="ABC" MerchantReferenceNumber="11235456" RequestDate="2014-8-22" RequestID="123456789456123" >
-< BillTo >
< FirstName > JOHN < /FirstName >
< LastName >smith< /LastName >
< Address1 >123 JOHN STREET < /Address1 >
< City >NEW York< /City >
< State >NY< /State >
< Zip >326544< /Zip >
< Email >JOHNSMITH@HOTMAIL.COM< /Email > < Country >US< /Country >
< Phone >30526445698< /Phone >
< IPAddress >111.11.111.111< /IPAddress >
< /BillTo >
< ShipTo >
< FirstName > JOHN < /FirstName >
< LastName >smith< /LastName >
< Address1 >123 JOHN STREET < /Address1 >
< City >NEW YORK< /City >
< State >NY< /State >
< Zip >326544< /Zip >
< Country >US< /Country >
< /ShipTo >
< Shipping >
< Method >oneday< /Method >
< Carrier/ >
< /Shipping >
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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