我有一个非常简单的类定义。 Sheetwriter类定义如下:
Option Explicit
'Works off of the ActiveCell
'Helps you write data into the cells
Private pCornerCell As String
Public Property Get CornerCell()
CornerCell = pCornerCell
End Property
Public Property Let CornerCell(Value As String)
pCornerCell = Value
Range(Value).Select
End Property
我收到一个我不明白的编译错误。 同一属性的属性过程的定义不一致,或者属性过程有可选参数。 我做错了什么?
最佳答案
Public Property Get CornerCell()
由于未指定返回类型,因此返回隐式Variant
。
Public Property Get CornerCell() As String
这将返回编译器在 Property Let
成员中看到的 String
,并解决您的问题。
FWIW,该 Range(Value).Select
语句根本不属于那里,并且您不想要处理事件单元格并洒水Select
和 Activate
语句无处不在。
参见How to avoid using Select in Excel VBA macros有关避免这种情况的一些提示。
关于excel - VBA错误: Definitions of property procedures for the same property are inconsistent,或属性过程有一个可选参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45037891/