VBA错误:相同属性的属性过程的定义不一致,或者属性过程有一个可选参数
我有一个非常简单的类定义。 课表作者定义如下:
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
,因为没有指定返回types。
Public Property Get CornerCell() As String
这是返回编译器在Property Let
成员中看到的String
,并修复了您的问题。
FWIW, Range(Value).Select
语句根本不属于那里,而且你不想在活动单元中工作,并且随处可见Select
和Activate
语句。
请参阅如何避免使用在Excel VBAmacros中select有关避免该问题的一些提示。