CustomXMLPart 方法 (Office)CustomXMLPart.Load method (Office)

使模板作者可以通过现有文件填充 CustomXMLPartAllows the template author to populate a CustomXMLPart from an existing file. 如果加载成功,则返回 TrueReturns True if the load was successful.

语法Syntax

表达式负载(FilePath)expression.Load (FilePath)

_表达式_一个返回**CustomXMLPart** 对象的表达式。expression An expression that returns a CustomXMLPart object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
FilePathFilePath 必需Required StringString 指向用户计算机或包含要加载的 XML 的网络上的文件。Points to the file on the user's computer or on a network containing the XML to be loaded.

返回值Return value

布尔值Boolean

示例Example

以下示例将添加一个自定义 XML 部件、使用一个文件中的 XML 填充该自定义 XML 部件,然后处理部件的节点。The following example adds a custom XML part, populates the custom XML part with XML from a file, and then manipulates the part's nodes.

Sub ShowCustomXmlParts() 
    On Error GoTo Err 
 
    Dim cxp1 As CustomXMLPart 
 
    With ActiveDocument 
        ' Example written for Word. 
 
        ' Add a custom XML part and then load the XML from a file. 
        Set cxp1 = .CustomXMLParts.Add 
        cxp1.Load "c:\invoice.xml" 
 
        Set cxn = cxp1.SelectSingleNode("//*[@quantity < 4]")  
        ' Insert a subtree before the single node selected previously. 
        cxn.InsertSubTreeBefore("<discounts><discount>0.10</discount></discounts>")   
               
        ' Delete custom XML part. 
        cxp1.Delete 
        cxn.Delete 
                 
    End With 
     
    Exit Sub 
                 
' Exception handling. Show the message and resume. 
Err: 
        MsgBox (Err.Description) 
        Resume Next 
End Sub

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.