将工作表传递给函数(excel vba)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2082810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:13:38  来源:igfitidea点击:

pass sheet to a function (excel vba)

excelvbaexcel-vba

提问by Matt Facer

I've been trying to pass a sheet in my workbook to a function, but it doesn't seem to be working. The function is

我一直在尝试将工作簿中的工作表传递给函数,但它似乎不起作用。功能是

Private Sub passToSheet(theData As Variant, Optional mySheet As Worksheet)

I have tried doing

我试过做

Dim mySheet as Worksheet
Set mySheet = "Results"

then to call the function

然后调用函数

passToSheet theData mySheet

but it doesn't seem to work. I'm not really sure what to google to get the right way to reference the worksheet though! Any help is much appreciated!

但它似乎不起作用。不过,我不太确定要谷歌什么才能找到正确的方法来引用工作表!任何帮助深表感谢!

回答by Vincent Ramdhanie

Use

'Set mySheet to worksheet
Set mySheet = Worksheets("Results")

to get a reference to the Worksheet.

获取对工作表的引用。