Running Macro on Model Load - Completes too soon.

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)<br><br>ConfiguratorMain<br><br>    MsgBox model.GetTitle()<br>End Sub‍‍‍‍‍‍‍‍‍‍‍‍<span class="line-numbers-rows"><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span></span>

Sub ConfiguratorMain()<br><br>Set swApp = Application.SldWorks<br>Set swModel = swApp.ActiveDoc<br><br>    If swModel Is Nothing Then<br>        MsgBox "No active part or assembly model found in SolidWorks." & Chr(13) _<br>        & "Please load/activate a SolidWorks part or assembly model and try again.", vbExclamation<br>    Else<br>        MainForm1.Show<br>    End If<br><br>End Sub<br><br><span class="line-numbers-rows"><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span><span>‍</span></span>
SolidworksApi/macros
Comments 1
ST
ST 2021-04-08

You don't need to call swApp.ActiveDoc

You already have the ModelDoc2 variable called "model" which is passed into Main. Simply pass that through to ConfiguratorMain:

Sub Main(model As SldWorks.ModelDoc2)

    ConfiguratorMain model

    MsgBox model.GetTitle()
End Sub

Sub ConfiguratorMain(model As SldWorks.ModelDoc2)

    Set swApp = Application.SldWorks

    If model 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
       'You probably need to pass model into MainForm1 as well. Create a public variable within MainForm1 and set it here:
       Set MainForm1.swModel = model
        MainForm1.Show
    End If

End Sub