Skip to Main Content
Excel 2003 Programming: A Developer's Notebook
book

Excel 2003 Programming: A Developer's Notebook

by Jeff Webb
August 2004
Intermediate to advanced content levelIntermediate to advanced
312 pages
8h 30m
English
O'Reilly Media, Inc.
Content preview from Excel 2003 Programming: A Developer's Notebook

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Microsoft® Office Excel 2003 Programming Inside Out

Microsoft® Office Excel 2003 Programming Inside Out

Curtis Frye, Wayne S. Freeze, Felicia K. Buckingham
Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
Office 2003 XML

Office 2003 XML

Simon St. Laurent, Mary McRae, Evan Lenz

Publisher Resources

ISBN: 0596007671Supplemental ContentCatalog PageErrata