excel - 将 Sub 作为参数传递
问题描述
我有一个子
Sub MySub1
MsgBox "I am ok!"
End Sub
然后我有一个带有参数的所谓“方法子”
Sub MySub2 (Parameter1, Parameter2, MethodName)
MsgBox Parameter1
MsgBox Parameter2
MethodName
End Sub
然后我想在我的主人身上运行整个链条。我尝试了以下方法:
Sub MasterSub
Dim Parameter1 As String
Dim Parameter2 As String
Dim MethodName As String
Parameter1 = "Ou"
Parameter2 = "Yes"
MethodName = MySub1
MySub2 Parameter1, Parameter2, MethodName
Dim
这给出了预期值或函数的错误。如何使这项工作?
解决方案
您需要创建Module
(如下面的屏幕截图所示):
然后粘贴这段代码:
Private Sub MySub1()
MsgBox "I am ok!"
End Sub
Private Sub MySub2(Parameter1, Parameter2, MethodName)
MsgBox Parameter1
MsgBox Parameter2
Application.Run MethodName
End Sub
Sub MasterSub()
Dim Parameter1 As String
Dim Parameter2 As String
Dim MethodName As String
Parameter1 = "Ou"
Parameter2 = "Yes"
MethodName = "MySub1"
MySub2 Parameter1, Parameter2, MethodName
End Sub
然后单击Run Sub/User Form
按钮(或单击F5
键)运行您的宏。
推荐阅读
- php - 改造中经常超时
- tensorflow - 加速 rcnn 的量化感知训练异常
- python - 如何定期清除 celery rabbitmq 中的队列?
- swift - 如何在 Watchkit 应用程序 swift 上拥有交互式地图?
- python - 使用 matplotlib 在 x 轴上绘制时间
- sapui5 - SAPUI5 BusyIndicator 周围的边界线错误
- jenkins - jenkins 无法根据来自 bitbucket 云的拉取请求触发构建
- android - AndroidX JetPack NavigationUI - 覆盖抽屉中非导航项的操作
- chocolatey - 从安装程序自动创建包巧克力
- android - 自定义 android 搜索视图