Respond to XML Events
The Workbook object provides events that occur before and after data is imported or exported through an XML map. You can use these events to control how the import/export occurs, respond to errors, or cancel the operation.
How to do it
For example, the following event procedures display information about import and export actions as they occur:
Private Sub Workbook_BeforeXmlImport(ByVal Map As XmlMap, _ ByVal Url As String, ByVal IsRefresh As Boolean, Cancel As Boolean) Debug.Print "BeforeImport", Map, Url, IsRefresh, Cancel End Sub Private Sub Workbook_BeforeXmlExport(ByVal Map As XmlMap, _ ByVal Url As String, Cancel As Boolean) Debug.Print "BeforeExport", Map, Url, IsRefresh, Cancel End Sub Private Sub Workbook_AfterXmlImport(ByVal Map As XmlMap, _ ByVal IsRefresh As Boolean, ByVal Result As XlXmlImportResult) Debug.Print "AfterImport", Map, Url, Result End Sub Private Sub Workbook_AfterXmlExport(ByVal Map As XmlMap, _ ByVal Url As String, ByVal Result As XlXmlExportResult) Debug.Print "AfterExport", Map, Url, Result End Sub
To cancel an import or export action, set the eventâs Cancel argument to True. The following code allows the user to cancel refreshing or importing data from the Orders_Map:
Private Sub Workbook_BeforeXmlImport(ByVal Map As XmlMap, _ ByVal Url As String, ByVal IsRefresh As Boolean, Cancel As Boolean) If Map.name = "Orders_Map" And Not IsRefresh Then res = MsgBox("This action will replace all the data " & _ "in this list. Do you ...
Get Excel 2003 Programming: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.