Results 1 to 2 of 2

Thread: XML Mapping in Excel Sheet

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    1
    Rep Power
    0

    XML Mapping in Excel Sheet

    Hi,

    I am New to this forum, please help me to create a macro!!!

    My requirement is like i am having an column in my excel sheet. the value of the column should be mapped to more than one field found on the xml structure. Say for example a column name Domain Name is having some value like "GRK" this should be mapped to XML structure Domain Name field. XML Source consist of Domain Name field at multiple places i need to map the column value to all this place. Is that possible.


    Thanks and Regards
    Ranjithkumar

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.eileenslounge.com/viewtopic.php?p=312533#p312533
    https://www.eileenslounge.com/viewtopic.php?f=44&t=40373&p=312499#p312499
    https://www.eileenslounge.com/viewtopic.php?p=311844#p311844
    https://archive.org/download/wlsetup-all_201802/wlsetup-all.exe
    https://www.eileenslounge.com/viewtopic.php?p=311826#p311826
    https://www.eileenslounge.com/viewtopic.php?f=37&t=40261&p=311783#p311783
    https://www.eileenslounge.com/viewtopic.php?p=310916#p310916
    https://www.eileenslounge.com/viewtopic.php?p=310720#p310720
    https://www.eileenslounge.com/viewtopic.php?f=56&t=40034&p=310171#p310171
    https://www.eileenslounge.com/viewtopic.php?p=310110#p310110
    https://www.eileenslounge.com/viewtopic.php?p=310024#p310024
    https://www.eileenslounge.com/viewtopic.php?p=309121#p309121
    https://www.eileenslounge.com/viewtopic.php?p=309101#p309101
    https://www.eileenslounge.com/viewtopic.php?p=308945#p308945
    https://www.eileenslounge.com/viewtopic.php?f=30&t=39858&p=308880#p308880
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 04-07-2024 at 12:50 PM.

  2. #2
    Senior Member LalitPandey87's Avatar
    Join Date
    Sep 2011
    Posts
    222
    Rep Power
    14
    Here you can find your node:

    Code:
    Option Explicit
    
    
    Const strNodeStartWith      As String = "//"
    Const strNoValueFound       As String = "NoGivenNodeFoundPleaseCheck"
    
    
    Sub HowToCall()
    
    
        Dim varArrValue()       As Variant
    
    
        varArrValue = ReadXmlNode("C:\Test.xml", "Domain Name")
        If varArrValue(LBound(varArrValue), UBound(varArrValue, 2)) <> strNoValueFound Then
            MsgBox "Node found you can loop to get values.", vbInformation, "XML Node"
        Else
            MsgBox "Given node not found.", vbInformation, "XML Node"
        End If
        
        Erase varArrValue
    
    
    End Sub
    
    
    Function ReadXmlNode(ByVal XMLFilePath As String, ByVal NodeToSearch As String) As Variant
    
    
        Dim xmlDoc                  As Object 'DOMDocument Object
        Dim xmlNodes                As Object 'IXMLDOMNodeList Object
        Dim xmlNode                 As Object 'IXMLDOMNode Object
        Dim lngCount                As Long
        Dim vararrValues()          As Variant
        
        Erase vararrValues
        Set xmlDoc = CreateObject("MSXML2.DOMDocument")
        xmlDoc.Load (XMLFilePath)
        If Left(NodeToSearch, 2) <> strNodeStartWith Then NodeToSearch = strNodeStartWith & NodeToSearch
        Set xmlNodes = xmlDoc.DocumentElement.SelectNodes(NodeToSearch)
        If xmlNodes.Length > 0 Then
            ReDim vararrValues(1 To xmlNodes.Length, 1 To 1)
            lngCount = 0
            For Each xmlNode In xmlNodes
                lngCount = lngCount + 1
                vararrValues(lngCount, 1) = xmlNode.Text
            Next xmlNode
        Else
            ReDim vararrValues(1 To 1, 1 To 1)
            vararrValues(1, 1) = strNoValueFound
        End If
        ReadXmlNode = vararrValues
        xmlDoc.abort
        
        Set xmlDoc = Nothing
        Set xmlNodes = Nothing
        Set xmlNode = Nothing
        lngCount = Empty
        Erase vararrValues
    
    
    End Function

Similar Threads

  1. Xml Mapping in Excel Macro
    By dhivya.enjoy in forum Excel Help
    Replies: 1
    Last Post: 10-18-2013, 04:11 PM
  2. Convert selected file to XML and save.
    By dhivya.enjoy in forum Excel Help
    Replies: 7
    Last Post: 10-09-2013, 01:32 PM
  3. Replies: 2
    Last Post: 09-30-2013, 03:40 PM
  4. Copy selected data to other excel sheet
    By dhiraj.ch185 in forum Excel Help
    Replies: 2
    Last Post: 02-02-2012, 06:23 AM
  5. Finding Last Used Row or Column In Excel Sheet
    By Rasm in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 04-14-2011, 03:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •