变量生命周期即变量在内存中与数据值绑定的时间跨度。
变量生命周期类型 | 变量声明方式 | 变量生命周期 |
Program Extent | Defined by the VBA specification or by the host application. | The entire existence of an active VBA Environment. |
Module Extent | A Module Variable Declaration or a static local variable declaration within a procedure. | The span from the point that the containing module is incorporated into an active VBA project to the point when the module or project is explicitly or implicitly removed from its VBA Environment. |
Procedure Extent | A procedure local variable or formal parameter declaration of a procedure. | The duration of a particular procedure invocation. |
Object Extent | A variable declaration within a class module. | The lifespan of the containing object. |
Aggregate Extent | A dependent variable (section 2.3.1) of an array or UDT variable. | The lifespan of the variable holding the containing aggregate data value (section 2.1.1). |