首页 > 解决方案 > 设置自定义对象参数时出现堆栈空间不足错误

问题描述

我有一个名为 Service 的自定义类模块,带有字符串参数。我通过创建this_service这样的对象来实例化该类:

Dim this_service As Service
Set this_service = New Service

然后我尝试将参数设置为任何字符串值,如下所示:

this_service.Key = "HELLO"

当我运行宏时,我得到 28 运行时错误,堆栈空间不足。

在我的类模块服务中,我有以下参数定义和方法调用:

Private pKey As String

Public Property Get Key() As String
    Key = pKey
End Property

Public Property Let Key(Value As String)
    Key = Value
End Property

我看不出我会收到此运行时错误的任何原因?

标签: vbaexcel

解决方案


其中Public Property Let应该是:

pKey = Value

现在它递归地(无限期地)调用setter。


推荐阅读