excel - VBA错误: Definitions of property procedures for the same property are inconsistent,或属性过程有一个可选参数

标签 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 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 语句根本不属于那里,并且您不想要处理事件单元格并洒水SelectActivate 语句无处不在。

参见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/

相关文章:

class - 为什么我不能 "implements"TypeScript 2.4+ 中的全可选接口(interface)?

c++ - 在类内部和外部定义的模板类的成员函数之间的区别

excel - 一次更改工作表中的多个命名单元格和范围

regex - 如何使用正则表达式提取具有特定单位的值并求和

excel - 选择行数可变的列中的所有数据

excel - 删除重复项的循环仅适用于第一次迭代

objective-c - 访问 ObjC 类别中的静态变量

vba - 在 VBA 中处理一个集合的嵌套 For 循环

excel - 从单元格复制时省略引号

sql - 连接操作中的语法错误-MS Access