Hi all, I'm trying to write a macro to create a file log that records every change of active document.
I would like to write to a file a list of date / time / filename of the active document (part/assembly/drawing).
Therefore the macro should trigger a function that write to a file every time the active document chages.
Following the suggestions I found on the following link
I created the following macro:
Main Module:
Sub main()
Dim MyClass As New Notification_Class
MyClass.MonitorSolidWorks
End Sub
Class Module: (Notification_Class)
Option Explicit
Dim WithEvents swApp As SldWorks.SldWorks
Dim MyModel As SldWorks.ModelDoc2
-------------------------
Public Sub MonitorSolidWorks()
Set swApp = Application.SldWorks
End Sub
--------------------------
Private Function swApp_ActiveDocChangeNotify() As Long
Dim Time As Date
Dim FileName As String
' Get active document
Set MyModel = swApp.ActiveDoc
' Open output file for writing document change log file
Open "c:\temp\swActiveDocLog.txt" For Output As #1
FileName = MyModel.GetPathName
Time = DateTime.Date & DateTime.Time
' Write to output file
Write #1, Time & "Active doc: " & FileName
' Close the output file
Close #1
End Function
I get no results. It seems the function will not run when the active document changes.
What's wrong?
Thanks in advance for your help.
SolidworksApi/macros