【问题标题】:VBA Error: Definitions of property procedures for the same property are inconsistent, or property procedure has an optional parameterVBA错误:同一属性的属性过程定义不一致,或者属性过程有一个可选参数
【发布时间】:2017-07-11 14:48:12
【问题描述】:

我有一个非常简单的类定义。 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

我收到一个我不理解的编译错误。 同一属性的属性过程定义不一致,或者属性过程有可选参数。 我做错了什么?

【问题讨论】:

    标签: excel vba class let


    【解决方案1】:
    Public Property Get CornerCell()
    

    这将返回一个隐式 Variant,因为没有指定返回类型。

    Public Property Get CornerCell() As String
    

    这将返回编译器在Property Let 成员中看到的String,并解决了您的问题。

    FWIW,Range(Value).Select 语句根本不属于其中,并且您不想要关闭活动单元格并将SelectActivate 语句到处散布。

    请参阅How to avoid using Select in Excel VBA macros 了解有关避免这种情况的一些提示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 2015-02-11
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 2019-11-13
      相关资源
      最近更新 更多