我有一个 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"