模块:
Option Explicit
Public notifyWrapper As Class1
Sub main()
Set notifyWrapper = New Class1
notifyWrapper.monitorSolidWorks
End Sub
类模块:
Option Explicit
Public WithEvents swApp As SldWorks.SldWorks
Public WithEvents swAssDoc As SldWorks.AssemblyDoc
Public WithEvents swDrawDoc As SldWorks.DrawingDoc
Public WithEvents swPartDoc As SldWorks.PartDoc
Private Function swApp_ActiveModelDocChangeNotify() As Long
Dim swModelDoc As SldWorks.ModelDoc2
Set swModelDoc = swApp.ActiveDoc
Select Case swModelDoc.GetType
Case SwConst.swDocASSEMBLY
Set swAssDoc = swModelDoc
Case SwConst.swDocDRAWING
Set swDrawDoc = swModelDoc
Case SwConst.swDocPART
Set swPartDoc = swModelDoc
End Select
Set swModelDoc = Nothing
End Function
Private Function swAssDoc_FileSaveAsNotify2(ByVal FileName As String) As Long
preSave FileName
End Function
Private Function swAssDoc_FileSaveNotify(ByVal FileName As String) As Long
preSave FileName
End Function
Private Function swDrawDoc_FileSaveAsNotify2(ByVal FileName As String) As Long
preSave FileName
End Function
Private Function swDrawDoc_FileSaveNotify(ByVal FileName As String) As Long
preSave FileName
End Function
Private Function swPartDoc_FileSaveAsNotify2(ByVal FileName As String) As Long
preSave FileName
End Function
Private Function swPartDoc_FileSaveNotify(ByVal FileName As String) As Long
preSave FileName
End Function
Public Sub monitorSolidWorks()
Set swApp = Application.SldWorks
End Sub
Sub preSave(sFileName As String)
MsgBox sFileName & " is about to be saved!"
End Sub