我对 VBA 代码相当陌生,当我尝试在我创建的类中运行此代码时遇到了编译错误。
Private pWorkDate As Date
Public Property Set WorkDate(value As Date)
Set pWorkDate = value
End Property
Public Property Get WorkDate() As Date
Set WorkDate = pWorkDate
End Property
这是我收到的错误消息:
Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter, a ParamArray, or an invalid Set final parameter
请原谅我的无知,但我一直在四处寻找,似乎无法找到我做错了什么。
最佳答案
它不喜欢您尝试使用用于对象引用的 set
,Date
类型的变量永远不可能是(它是原始类型(如 integer
) 不是对象类型(比如你的类))。
更改为 Let
并且不使用 Set
:
Public Property Let WorkDate(value As Date)
pWorkDate = value
End Property
Public Property Get WorkDate() As Date
WorkDate = pWorkDate
End Property
关于为 Date 对象设置属性的 VBA 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16110315/