I have a VBA Add-In which is supposed to add functionality to several worksheets. I have a class to listen for worksheet events and trigger macros. This works but I can't seem to call private macros with parameters from it.
My event listener is in a class module and is this:
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
It is initialized on opening the workbook in a module like so:
Sub Auto_Open()
Set clsAppEvents = New clsApplicationEvents
End Sub
And the macro I'm trying to call is in a separate module again and takes the form:
Private Sub Worksheet_Change(ByVal Target As Range)
'Do some work on range
End Sub
I've tried the following ways of calling the macro and none have worked so far:
Call Application.Run("Worksheet_Change", "Source")
Application.Run "Worksheet_Change", "Source"
Application.Run "Worksheet_Change" "Source"
Sourceas a string instead of a Range object. Try removing the quotes around Source in your call to Run.