Application of common objects

Source: Internet
Author: User

Objects are the operands of our Excel and our programs. such as cells, workbooks. Each of our operations for Excel is actually an action on the corresponding object. For example, select a cell, save a worksheet.

Objects are stored in the object model, and more than 2013 versions seem to have no offline documentation, only online: https://msdn.microsoft.com/ZH-CN/library/ff194068.aspx

Each object has its own properties and methods, which finally form the complete event.

Remember common objects:

Application object:

Represents the entire program of Excel, so it is the top level.

ScreenUpdating Property

Application.screenupdting=true (the default is true), the effect is that when the program has more than one calculation step, VBA default is a display of each calculation results, to false, you can let the program after the execution of the results, can improve the efficiency of the program. (Though it doesn't feel right)

Compare the following two-paragraph procedure:

In the first piece of code, the program has four steps, which are executed sequentially and displayed.

In the second piece of code, four steps are executed sequentially, and the final step shows the results simultaneously.

DisplayAlerts Property

See the word alert probably knows what it is.

A program to delete a worksheet:

After you run the program, a warning dialog pops up asking if you want to delete the worksheet, which can affect your efficiency.

(although I still feel that it is not practical, my worksheet is not much to need to delete the code)

If at first add:

Application.displayalerts=false (default = True)

The warning is not displayed and the action is performed directly. Again, at the end, remember to change the default value to True.

EnableEvents Property

This property is used to enable or suppress events.

The event here refers to an executable operation in the program, code, such as a selected cell. Similarly, if we want to prohibit an event from executing, precede his line of code with:

Application.enableevents=false

Also remember to change back to the default value TRUE.

WorksheetFunction Property

There are many functions in VBA that do not, (before even the sum is useless) use this property to invoke part of the worksheet function,

For example, I want to calculate the sum between A1 to A10, in VBA,

The first, the direct use of the function:

Cells ("A") = "=sum (a1:a10)", which is equivalent to writing a formula to a cell, but not necessary.

Second, call properties:

Cells ("A") =application.worksheetfunction.sum (Range ("a1:a10"))

Remember that you need to combine range to select the sum area.

In addition, if there are functions (not many) that are already in VBA, they cannot be called in this way.

Application the Common Properties

Application of common 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.