【问题标题】:calling methods from another sheet in the same book VBA从同一本书VBA中的另一张纸调用方法
【发布时间】:2021-07-29 20:16:45
【问题描述】:

我想在 VBA 中另一个模块的 Excel 工作表中使用一个函数。 但是我不知道为什么下面的代码会导致错误。

在工作表“项目”中:

Public Function get_value() As String
    get_value = aBox.Value 'aBox is a text box in the sheet
End Function

在另一个模块中:

Function hoge(proj As Worksheet) As String
    Dim name as string
    name = proj.get_value() 'This causes an error "method or data member not found"

有什么建议吗?

【问题讨论】:

    标签: excel vba reference


    【解决方案1】:

    通用 Worksheet 对象没有属性 get_value,因此当您使用 proj As Worksheet 声明参数时,VBA 需要使用通用工作表对象。

    试试proj As Object

    【讨论】:

    • 成功了!非常感谢。我误会了,一旦我在工作表中做了一个函数,就可以用工作表名和函数名来调用它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    相关资源
    最近更新 更多