在Word文档中迭代CustomXmlDocument

页面导航:首页 > 软件编程 > vb.net > 在Word文档中迭代CustomXmlDocument

在Word文档中迭代CustomXmlDocument

来源: 作者: 时间:2016-01-18 16:54 【

以下代码是一个VBA Form中的,用来迭代CustomXmlDocument。[vb]Private Sub TreeView1_BeforeLabelEdit(Cancel As Integer)End SubPrivate Sub UserForm_Activate() Dim oCustXMLPart As CustomXMLP...
以下代码是一个VBA Form中的,用来迭代CustomXmlDocument。
[vb] 
Private Sub TreeView1_BeforeLabelEdit(Cancel As Integer) 
 
End Sub 
 
Private Sub UserForm_Activate() 
    Dim oCustXMLPart As CustomXMLPart 
    Dim oNode As CustomXMLNode 
    Dim oNodeChild As CustomXMLNode 
    Dim oNodeChildChild As CustomXMLNode 
    Dim i As Long 
    Dim tRoot As Node 
     
    On Error Resume Next 
    ActiveDocument.CustomXMLParts(4).Delete 
    On Error GoTo 0 
    Set oCustXMLPart = ActiveDocument.CustomXMLParts.Add 
    oCustXMLPart.LoadXML ("<DocElement><Name>Joe</Name><Age>41</Age><Multi><Item1>A</Item1><Item2>B</Item2></Multi></DocElement>") 
    Set oNode = oCustXMLPart.DocumentElement 
    Set tRoot = TreeView1.Nodes.Add 
    tRoot.Text = "DocElement" 
    tRoot.Key = "DocElement" 
    Iterator oNode, tRoot 
End Sub 
 
Sub Iterator(ByRef Element As CustomXMLNode, ByRef tNode As Node) 
    Dim Childe As CustomXMLNode 
    Dim subNode As Node 
    For Each Childe In Element.ChildNodes 
        If Childe.NodeType = msoCustomXMLNodeText Then 
            Set subNode = TreeView1.Nodes.Add(tNode.Key, tvwChild, Childe.XPath, Childe.Text) 
        ElseIf Childe.NodeType = msoCustomXMLNodeElement Then 
            Set subNode = TreeView1.Nodes.Add(tNode.Key, tvwChild, Childe.XPath, Childe.BaseName) 
            If Childe.HasChildNodes Then 
                Iterator Childe, subNode 
            End If 
        End If 
    Next 
End Sub 
作者:TX_OfficeDev
Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<