将工作表传递给函数(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
pass sheet to a function (excel 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.
获取对工作表的引用。

