Application. enableevents = false (true)

Source: Internet
Author: User
Private sub worksheet_change (byval target as range)

Dim irow as integer

Irow = target. Row

Application. enableevents = false

Cells (irow, 3) = cells (irow, 3) + cells (irow, 2)

Application. enableevents = true

End sub

The purpose of this program is to input a new number in B2, C2 will display the new number entered in B2 plus the original number of C2 on C2.

If the application. enableevents = false program is added to it, the execution is fine.

Now add "'" before application. enableevents = false and application. enableevents = true (the following code ).

The purpose of adding "'" before the program is to convert the text after "'" into the description text. When the program is executed, the description text is skipped and the description text content is not executed.

After the "'" symbol is added before the program, the text turns green.

When you execute the second program, you will find that C2 will not present the results as you requested.

This is the so-called chain reaction of events.

Private sub worksheet_change (byval target as range)

Dim irow as integer

Irow = target. Row

'Application. enableevents = false

Cells (irow, 3) = cells (irow, 3) + cells (irow, 2)

'Application. enableevents = true

End sub

Another example is:

This example disables the event before saving the file so that the beforesave event cannot be triggered.

Application. enableevents = false
Activeworkbook. Save
Application. enableevents = true

 

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.