Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I want to read XML data on EXCEL sheet. Design of Excel is like this ....

Name = John

Address = Sydney.

Mob= 0346576456

here Left Side has fixed label and on the Right side XML data .

So I want to show that data accordingly specific Cells.

Please tell me Can we show this directly by Importing XML File. OR TELL ME SOME MACRO CODING


-John
Posted
Comments
Richard MacCutchan 25-Oct-13 10:41am    
OR TELL ME SOME MACRO CODING
Don't shout. People here are perfectly capable of reading normal case text.
As to your question, look at http://www.excel-spreadsheet.com/vba/inputoutput.htm.
Member 10272175 26-Oct-13 10:30am    
Sir , This is my code to extract data from XML File on excel cells. however I am getting error that "User defined type not defined" please help me

Private Sub CommandButton1_Click()



Sheet1.Activate
Range("F9:F21").ClearContents
Range("C6:C6").ClearContents
Range("f6:f6").ClearContents
Dim xml_doc As New DOMDocument
Dim brtn As Boolean
Dim onode As IXMLDOMElement
Dim elst As IXMLDOMNodeList
Dim chnode As IXMLDOMElement
Dim chnode1 As IXMLDOMElement
brtn = xml_doc.Load("C:\My Documents\Form Data.xml")

intr = 2
If brtn Then

' Set onode = xml_doc.selectSingleNode("//FullNationalNumber")
' acc = Trim(onode.Text)
'
' If acc = "" Then
' Set onode = xml_doc.selectSingleNode("//ReferenceNumber")
' Sheet1.Cells(6, 3) = onode.Text
' End If

For Each onode In xml_doc.SelectNodes("//ExistingService")
If onode.HasChildNodes Then
For Each chnode In onode.ChildNodes
nm = chnode.nodeName
If nm = "FullNationalNumber" Then
Sheet1.Cells(6, 3) = chnode.Text

End If
Next
End If
Next


For Each onode In xml_doc.SelectNodes("//ExistingAccount")
If onode.HasChildNodes Then
For Each chnode In onode.ChildNodes
nm = chnode.nodeName
If nm = "AccountNumber" Then
acc = Trim(chnode.Text)
If acc <> "" Then
Sheet1.Cells(6, 6) = "'" & chnode.Text
End If

End If
If nm = "FullNationalNumber" Then
acc = Trim(chnode.Text)
If acc <> "" Then
Sheet1.Cells(6, 6) = "'" & chnode.Text
End If

End If

Next
End If
Next






Set onode = xml_doc.SelectSingleNode("//CIDN")
Sheet1.Cells(9, 3) = onode.Text

Set onode = xml_doc.SelectSingleNode("//ABN")
Sheet1.Cells(10, 3) = onode.Text
Set onode = xml_doc.SelectSingleNode("//ACN")
Sheet1.Cells(11, 3) = onode.Text
Set onode = xml_doc.SelectSingleNode("//BusinessName")
Sheet1.Cells(12, 3) = onode.Text

'// customer Contacht
For Each onode In xml_doc.SelectNodes("//ContactDetails")
If onode.HasChildNodes Then
For Each chnode In onode.ChildNodes
nm = chnode.nodeName
If nm = "ContactName" Then
Sheet1.Cells(14, 3) = chnode.Text
ElseIf nm = "PhoneNumber" Then
Sheet1.Cells(15, 3) = chnode.Text
ElseIf nm = "EmailAddress" Then
Sheet1.Cells(16, 3) = chnode.Text
End If
Next
End If
Next

Set onode = xml_doc.SelectSingleNode("//AccountNumber")
Sheet1.Cells(18, 3) = onode.Text

Set onode = xml_doc.SelectSingleNode("//CustomerWants")
Sheet1.Cells(22, 3) = onode.Text
Set onode = xml_doc.SelectSingleNode("//CustomerHas")
Sheet1.Cells(21, 3) = onode.Text
Set onode = xml_doc.SelectSingleNode("//OwnershipCode")
Sheet1.Cells(19, 3) = onode.Text

'// Site Address
For Each onode In xml_doc.SelectNodes("//SiteAddress")
If onode.HasChildNodes Then
For Each chnode In onode.ChildNodes
nm = chnode.nodeName
If nm = "Address1" Then
Sheet1.Cells(25, 3) = chnode.Text
ElseIf nm = "Address2 " Then
Sheet1.Cells(26, 3) = chnode.Text
ElseIf nm = "Suburb" Then
Sheet1.Cells(27, 3) = chnode.Text
ElseIf nm = "State" Then
Sheet1.Cells(28, 3) = chnode.Text
ElseIf nm = "Postcode" Then
Sheet1.Cells(29, 3) = chnode.Text
End If
Next
End If
Next
Set onode = xml_doc.SelectSingleNode("//SiteAd

1 solution

Have you tried "Get external data" -> "Other sources"? Check out this link:
http://blogs.msdn.com/b/hovsep/archive/2007/07/11/excel-2007-how-to-connect-to-and-import-data-from-an-xml-web-service.aspx[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900