我有一个VBA加载项,它应该为几个工作表添加功能。我有一个类来监听工作表事件和触发宏。这有效,但我似乎无法调用带有参数的私有宏。
我的事件监听器位于类模块中,并且是:
Option Explicit
Private WithEvents App As Application
Private Sub Class_Initialize()
Set App = Application
End Sub
Private Sub App_SheetChange(ByVal Sh As Object, ByVal Source As Range)
On Error GoTo Finish
App.EnableEvents = False
Call Application.Run("Worksheet_Change", "Source")
Finish:
App.EnableEvents = True
End Sub
在如下模块中打开工作簿时初始化:
Sub Auto_Open()
Set clsAppEvents = New clsApplicationEvents
End Sub
我想要调用的宏再次位于一个单独的模块中,并采用以下形式:
Private Sub Worksheet_Change(ByVal Target As Range)
'Do some work on range
End Sub
我已经尝试了以下调用宏的方法,到目前为止还没有工作:
Call Application.Run("Worksheet_Change", "Source")
Application.Run "Worksheet_Change", "Source"
Application.Run "Worksheet_Change" "Source"
答案 0 :(得分:2)
Run的参数不一定都是字符串,所以
Application.Run "Worksheet_Change", "Source"
应该是
Application.Run "Worksheet_Change", Source