相关疑难解决方法(0)

缓慢的“属性获取”和“函数”过程

我遇到了一个令人讨厌的 VBA 错误,它使Property Get过程调用变得非常慢。这很可能是由于最近的 Office 更新(我有 Office365)造成的。它仅影响 32 位 CPU 上的 Excel。

错误

考虑一个Class1仅使用代码调用的类:

Option Explicit

Public Property Get Something() As Long: End Property
Run Code Online (Sandbox Code Playgroud)

基本上,一个Get返回零的属性。

运行以下代码时(在标准 .bas 模块中):

Public Sub TestSpeed()
    Const iterations As Long = 10000
    Dim i As Long
    Dim t As Double
    Dim coll As New Collection
    '
    t = Timer
    For i = 1 To iterations
        coll.Add New Class1
        CallGet coll.Item(coll.Count)
    Next i
    Debug.Print iterations & " loops took " …
Run Code Online (Sandbox Code Playgroud)

excel vba

5
推荐指数
1
解决办法
479
查看次数

标签 统计

excel ×1

vba ×1