VBA:调用带有多个参数的另一个工作表上的子 [英] VBA: Calling a sub on another worksheet with multiple arguments

查看:41
本文介绍了VBA:调用带有多个参数的另一个工作表上的子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力使用位于另一个工作表上的参数来调用过程(子).我可以在另一个工作表上调用一个过程.我可以调用带有参数的过程.但是,将两者结合在一起会使我头疼.

I've been struggling for a while to call a procedure (sub) with arguments that is located on another worksheet. I can call a procedure on another worksheet. I can call a procedure with arguments. But combining the two causes me headache's.

这就是我现在拥有的:

Private Sub Workbook_Open()
Call Sheet2.FillCombo("Mngt Dashboard", "ComboMonth")
'Sheet2.FillCombo"Operational Dashboard", "ComboMonth2"
End Sub

我尝试了两种语法调用该过程,但是都导致下标超出范围(9)".这是被调用的过程(位于sheet2上):

I tried both syntaxis for calling the procedure but both result in 'subscript out of range (9)'. Here's the procedure being called (located on sheet2):

Sub FillCombo(SheetName As String, ObjName As String)
Dim objCombo As Object
Set objCombo = ActiveWorkbook.Sheets(SheetName).OLEObjects(ObjName).Object
objCombo.Clear
objCombo.AddItem.....
...
End Sub

有没有人可以向我展示光明?

Is there anyone out there that can show me the light?

谢谢,马克

推荐答案

在第2行上,尝试删除括号:

On Line 2, try dropping the parenthesis:

Sheet2.FillCombo "Mngt Dashboard", "ComboMonth"

这篇关于VBA:调用带有多个参数的另一个工作表上的子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆