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