VBA Error: Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter
VBA Error: Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameter
我有一个非常简单的 Class 定义。
Class 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()
这是 return 隐式 Variant
,因为没有指定 return 类型。
Public Property Get CornerCell() As String
那是 return编译器在 Property Let
成员中看到的 String
,并解决了您的问题。
FWIW,那个 Range(Value).Select
语句根本不属于那里,你不想 关闭活动单元格并撒上 Select
和 Activate
语句无处不在。
请参阅 How to avoid using Select in Excel VBA macros 了解有关避免这种情况的一些提示。
我有一个非常简单的 Class 定义。 Class 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()
这是 return 隐式 Variant
,因为没有指定 return 类型。
Public Property Get CornerCell() As String
那是 return编译器在 Property Let
成员中看到的 String
,并解决了您的问题。
FWIW,那个 Range(Value).Select
语句根本不属于那里,你不想 关闭活动单元格并撒上 Select
和 Activate
语句无处不在。
请参阅 How to avoid using Select in Excel VBA macros 了解有关避免这种情况的一些提示。