Respond to an event
virtual void Update( CXlBeforeSaveEventArgs* e ); |
A pointer to an event arguments object is sent to the Update method.
Derived classes should implement this function, which is the event handler for the XLL+ event model.
The code below defines a class derived from CXlWorkbookBeforeSaveEventStaticObserver, implements an Update method which is called when the event occurs, and instantiates an instance of the new class.
Note that this particular Update method uses CXlBeforeSaveEventArgs::SetCancel to cancel the event, and prevent the workbook from being saved, unless it is being saved under a new name, using the Save As user interface.
// Define a class derived from CXlWorkbookBeforeSaveEventStaticObserver class CMyWorkbookSaveEventObserver : CXlWorkbookBeforeSaveEventStaticObserver { public: // This method will be called during the XlWorkbookBeforeSave event. virtual void Update(CXlBeforeSaveEventArgs* e) { CXllApp::XlMessageBox(_T("Saving ") + e->GetBookName(), XlMessageBoxTypeInformation); if (!e->GetSaveAsUI()) e->SetCancel(true); } }; // Create an instance of the class CMyWorkbookSaveEventObserver myWorkbookSaveObserver;
Header: xlpevents.h
CXlWorkbookBeforeSaveEventStaticObserver Class | CXlWorkbookBeforeSaveEventStaticObserver Methods