Events for "VBA Programming" 13.Workbook objects

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.