Article ID: 158244
Article Last Modified on 10/11/2006
Public WithEvents appevent As Application
The WithEvents keyword makes the appevent variable available in the
Object drop-down in the Class1 (Code) module window.
Private Sub appevent_WindowResize(ByVal Wb As Excel.Workbook, _
ByVal Wn As Excel.Window)
End Sub
Public WithEvents appevent As Application
Private Sub appevent_WindowResize(ByVal Wb As Excel.Workbook, _
ByVal Wn As Excel.Window)
MsgBox "you resized a window"
End Sub
Next, you have to create an instance of the class and then set the
appevent object of the instance of the Class1 to Application. This is
because when you declare a variable, WithEvents, at design time, there
is no object associated with it. A WithEvents variable is just like any
other object variable - you have to create an object and assign a
reference to the object to the WithEvents variable.
Dim myobject As New Class1
Sub Test()
Set myobject.appevent = Application
End Sub
Sub test()
Set myobject.appevent = Nothing
End Sub
class module
Additional query words: vbe 8.00 XL97 vba
Keywords: kbdtacode kbfaq kbhowto kbprogramming KB158244