Richard Kendrew

Running Macro on Model Load - Completes too soon.

Discussion created by Richard Kendrew on Jan 3, 2020
Latest reply on Jan 3, 2020 by Simon Turner

I've used the code from the below link to run a macro automatically when the model is opened.

Run VBA macro on model load using macro feature and SOLIDWORKS API 

 

The issue i'm having is that its opening the userform before the model has fully loaded so i'm getting the 'no model open' response.

 

Sub Main(model As SldWorks.ModelDoc2)

ConfiguratorMain

    MsgBox model.GetTitle()
End Sub

 

Sub ConfiguratorMain()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc

    If swModel Is Nothing Then
        MsgBox "No active part or assembly model found in SolidWorks." & Chr(13) _
        & "Please load/activate a SolidWorks part or assembly model and try again.", vbExclamation
    Else
        MainForm1.Show
    End If

End Sub

Outcomes