Basic knowledge of VBA

Source: Internet
Author: User

The difference between dim,static and Public,private in VBA reproduced article: from The tea blog http://blog.sina.com.cn/19850701xx

1 . Public and Private are generally used to define global variables, or they can be used in classes.

1-1. The difference is: The former defines a public variable, and if used in a module, the entire application can use the variable it defines, which is a common attribute if used in a class.

[Private] While the latter defines a private variable, if used in a module, then only the module can access its defined variables, if used in a class, then it is a private property.

2. Dim and Static are typically used internally within a procedure (sub or function), and the variables they define can only be accessed within the procedure.

2-1. The difference is: [Dim] The former defines a dynamic variable, and once the process is finished, the memory occupied by the variable is reclaimed by the system, and the data stored by the variable is destroyed.

[Static] The latter defines a static variable, which means that the memory occupied by the variable will not be reclaimed after the process is over, and the data will of course not be destroyed, so that the data will persist the next time you call the process.

Public and static, by contrast, have the effect of preserving data from destruction, but the former is appropriate for variables that all processes may access, while the latter minimizes the scope of the variable (which is accessed only within the process).

Basic knowledge of VBA

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.