1

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

1 回答 1

2

Run 的参数不必都是字符串,所以

Application.Run "Worksheet_Change", "Source"

应该

Application.Run "Worksheet_Change", Source
于 2013-07-29T15:00:41.750 回答