gpt4 book ai didi

vba - Excel vba - 将工作表传递给公共(public)函数

转载 作者:行者123 更新时间:2023-12-03 00:20:48 25 4
gpt4 key购买 nike

我有一个公共(public)职能:

Public Function Test(wrs As Worksheet, arr As Variant) As Variant

我有主子:

Sub Main()
Dim ws as Worksheet
Dim out, in

ws = ThisWorkbook.Sheets("Sheet1")

out = Test (ws, in)

调用测试时我收到“ByRef 参数类型不匹配”错误。

最佳答案

使用 Set 关键字,如下所示:

set ws = ThisWorkbook.Sheets("Sheet1") 

编辑:

然后确保您也设置了函数的返回值。像这样:

Public Function Test() As Variant
Set Test = ActiveSheet
End Function

Public Sub TestMe()
Debug.Print Test.name
End Sub

关于vba - Excel vba - 将工作表传递给公共(public)函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46053828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com