How to: Add Custom XML Parts to Document-Level Customizations
You can store XML data in a Microsoft Office Excel workbook or Microsoft Office Word document by creating a custom XML part in a document-level customization. For more information, see Custom XML Parts Overview.
Applies to: The information in this topic applies to document-level projects for Excel and Word. For more information, see Features Available by Office Application and Project Type.
|
To add a custom XML part to an Excel workbook
Add a new CustomXMLPart object to the CustomXMLParts collection in the workbook. The CustomXMLPart contains the XML string that you want to store in the workbook.
Add the
AddCustomXmlPartToWorkbookmethod to theThisWorkbookclass in a document-level project for Excel.Call the method from other code in your project. For example, to create the custom XML part when the user opens the workbook, call the method from the
ThisWorkbook_Startupevent handler.
To add a custom XML part to a Word document
Add a new CustomXMLPart object to the CustomXMLParts collection in the document. The CustomXMLPart contains the XML string that you want to store in the document.
Add the
AddCustomXmlPartToDocumentmethod to theThisDocumentclass in a document-level project for Word.Call the method from other code in your project. For example, to create the custom XML part when the user opens the document, call the method from the
ThisDocument_Startupevent handler.
For simplicity, this example uses an XML string that is defined as a local variable in the method. Typically, you should obtain the XML from an external source, such as a file or a database.
Custom XML Parts Overview
How to: Add Custom XML Parts to Documents by Using VSTO Add-Ins