Excel VBA错误:同一属性的属性过程定义不一致,或者属性过程具有可选参数

Excel VBA错误:同一属性的属性过程定义不一致,或者属性过程具有可选参数,excel,vba,class,let,Excel,Vba,Class,Let,我有一个非常简单的类定义。 类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 C

我有一个非常简单的类定义。 类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()
这将返回一个隐式的
变量
,因为没有指定返回类型

Public Property Get CornerCell() As String
这将返回编译器在属性Let成员中看到的
字符串
,并修复您的问题

FWIW,即
范围(值)。Select
语句根本不属于该范围,并且您不希望脱离活动单元格,将
Select
active
语句散布到任何地方

有关避免这种情况的一些提示,请参阅