Inserting custom XML into an open file: Can it be done?

I want to insert a custom XML part into an Open XML file.Problem: The file is currently open in Microsoft Excel 2007.

Is there any way to do this?

Using XML Mapping, I'm generating an XML file that I want to place inside the Open XML file after an event fires (i.e. the user clicks an export button). However, since the file is open, I don't think it will allow me to perform any functions using the Open XML object model. Creating a copy of the file, modifying it, and saving it doesn't seem like it would be ideal because then I'd have to reload the file in Excel. This would be very disruptive for the user.

What's the division of labor between the Excel 2007 Object Model and the Open XML API? Can the two coexist at all?

Or, do I have to always have to close whatever Office application I'm using before I do anything with the Open XML API?

[903 byte] By [ClaySmith] at [2008-2-23]
# 1

After doing some searching on MSDN I found the answer: Yes, it is possible.

In VBA in Excel, I just ended up doing something like this:

Code Snippet

' Exports XML Map and stores it in the Open XML package

Sub Export_XML()

Dim result As XlXmlExportResult
Dim exportXML As String

' Get XML Map Export XML
result = ActiveWorkbook.XmlMaps("Project_Map").exportXML(exportXML)

If result = XlXmlExportResult.xlXmlExportSuccess Then
ActiveWorkbook.CustomXMLParts.Add (exportXML)
Else
MsgBox ("Export failed!")
End If

End Sub

ClaySmith at 2007-10-2 > top of Msdn Tech,Office Live Development,Microsoft SDK for Open XML Formats...