为 Date 对象设置属性的 VBA 编译错误

标签 vba compiler-errors

我对 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

请原谅我的无知,但我一直在四处寻找,似乎无法找到我做错了什么。

最佳答案

它不喜欢您尝试使用用于对象引用的 setDate 类型的变量永远不可能是(它是原始类型(如 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/

相关文章:

ios - 如何解决显示类似文件名被使用两次的错误

Java Magic Square - 求和列和求和行错误

java - "Non-static method cannot be referenced from a static context"错误

c++ - 将Qt C++与lp_solve集成-编译器错误

vba - 在本地处理预期错误的模式,重新抛出意外错误

sql - 自动刷新 Excel ODC 连接和数据透视表,无需打开文件 PowerShell

vba - 为什么 VBA 中没有 float ?

excel - VBA 代码中的多个 IF 语句可根据另一列从多列中提取不同的单元格值。

mysql - SQL 查询 - ORDER BY

c++ - 尝试编译我的wxWidgets程序时出现 “is_enum not declared in this scope”错误