MACRO LIBRARY

Kill listener class after event notification fires

Free public access. No account or subscription required.

Files

Kill listener class after event notification fires

Code

Module: mMain

'Demonstrates how to kill a listener class after a notification fires once.
    
'Instructions: run this macro, open a part, close the part, then re-open the part. You should _
    only see the message box once.
    
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
    
Public listener As clsListener
    
Sub main()
    Set listener = New clsListener
    listener.connect
End Sub

Class: clsListener

Dim WithEvents swApp As SldWorks.SldWorks
    
Sub connect()
    Set swApp = Application.SldWorks
End Sub
    
Private Function swApp_FileOpenNotify2(ByVal FileName As String) As Long
    MsgBox "You won't see this message the next time you open a part."
    Set listener = Nothing
End Function