The workbook event is used to respond to the action on the Workbook object.
"BeforeClose Event"
The Bforeclose event is used to respond to a window close operation
In the Project Explorer, double-click the "ThisWorkbook" object, pop up the "ThisWorkbook" window, and select Workbook,beforeclose
and write the following code in the window:
"Code Area"
private sub workbook_beforeclose ( Cancel as boolean ) if thisworkbook.saved = false then Thisworkbook.save msgbox " The workbook has changed, saved , vbOKOnly, " test beforeclose event " cancle = true end
if end Sub
Then save it. After saving, reopen excle, edit and exit directly. The following results will appear
"Results show"
"BeforeSave Event"
The BeforeSave is used in response to the save operation, and the BeforeSave action is triggered when the save operation occurs
Consistent with BeforeClose event operations
"Code Area"
Private SubWorkbook_beforesave (ByValSaveAsUi as Boolean, cancel as Boolean) Sel=MsgBox("Do you really want to save the changes to the workbook? ", vbYesNo,"Test BeforeSave Events") Ifsel = vbno ThenCancel=True End IfEnd Sub
"Results show"
"Windowsactivate Event"
The Windowsactivate event is used to save the action that responds to the activation window, and when the window is activated, the code inside the function is executed first, followed by the activation window
"Code Area"
Private SubWorkbook_windowsactivate (ByValWn asWindow)MsgBox "Welcome to the Excle 2013 spreadsheet handler", vbOKOnly,"Test Windowsactivate Events"End SubPrivate SubWorkbook_windowresize (ByValWn asWindow)MsgBox "you have adjusted the window size of the Excle 2013 application", vbOKOnly,"Test Windowsactivate Events"End Sub
Adjust the window as follows for large hours:
"Effect Show"
Events for "VBA Programming" 13.Workbook objects