I'm having issues raising a custom event.
I have the following code in Class1 module:
and the following in ThiwWorkbook module:
The problem is that
I've set a breakpoint in
I have the following code in Class1 module:
VBA Code:
Option Explicit
Private WithEvents app As Application
Private rng As Range
Public Event DAD(OldRange As Range, NewRange As Range, Worksheet As Worksheet)
Private Sub app_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim r As Range
If (rng Is Nothing) Then Exit Sub
If (rng.Address <> Target.Address) Then
If (rng.Count = Target.Count) Then
RaiseEvent DAD(Target, rng, Sh)
End If
End If
End Sub
Private Sub app_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Set rng = Target
End Sub
Private Sub Class_Initialize()
Debug.Print "Class init"
Set app = Application
End Sub
and the following in ThiwWorkbook module:
VBA Code:
Option Explicit
Private WithEvents DnD As Class1
Dim cls As New Class1
Private Sub DnD_DAD(OldRange As Range, NewRange As Range, Worksheet As Worksheet)
Debug.Print "hello, summit should have occurred"
End Sub
Private Sub Workbook_Open()
Set cls = New Class1
End Sub
The problem is that
Private Sub DnD_DAD
never fires. When opening the workbook, the class is initialised as 'Class Init' is displayed in the immediate window, so I know at least this part is working. Does anyone know why Private Sub DnD_DAD
is not triggered when cells are moved? I've set a breakpoint in
Sub app_SheetChange
and have stepped through to the RaiseEvent, so I also know that this actually being called too.