GetEquationMgr not returning anything?

Hello,

I'm trying to create a macro that opens a read-only file from a server location, saves a writable copy to the users hard drive, then opens that part and changes some equations based on input through an excel worksheet.

What's happening is the part is opened, saved as copy, all parts are closed. The new part is opened, which is where stuff breaks down. The equation manager isn't returning anything when being called and the subroutine doesn't run. I can't really find anyone with my problem, so I'm at a loss.

The part most definitely has equations to change, so that's not the problem.

Here's my code:

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swEqnMgr As SldWorks.EquationMgr
Dim xlApp As Excel.Application
Dim xlWb As Excel.Workbook
Dim strPart As String
Dim lErrors As Long
Dim lWarnings As Long
Dim fLength As Long
Dim fHeight As Long
Dim fWidth As Long
Dim pin_centers As Long
Dim savefilepath As String
Dim filename As String
Dim partsaved As Boolean
Dim NewFileOpenPath As String
Dim i As Integer
Dim vSplit As Variant
Dim boolstatus As Boolean

Sub main()

   
   
    Set xlApp = Excel.Application
    Set xlWb = xlApp.ActiveWorkbook
   
    fLength = xlWb.ActiveSheet.Cells(2, 2).value
    fWidth = xlWb.ActiveSheet.Cells(2, 3).value
    fHeight = xlWb.ActiveSheet.Cells(2, 4).value
    pin_centers = xlWb.ActiveSheet.Cells(2, 5).value
    'rollover_trunion_state = xlWb.ActiveSheet.Cells(2, 6).value
    savefilepath = Application.DefaultFilePath
    strPart = "C:\Users\admin\Desktop\stuff\solid model templates\f template current\test\test wo design table - copy.sldprt"
    filename = fLength & " x " & fWidth & " x " & fHeight & " with " & pin_centers & "pinctrs"
    NewFileOpenPath = savefilepath & "\" & filename & ".sldprt"
   
  
   
    If pin_centers < (fLength + 2) Then
        pin_centers = InputBox("Your pin center distance looks a little wacky. Why don't you try and enter something more sensible?", "Pin center distance check", CStr(ActiveSheet.Cells(2, 5)))
    End If
   
    On Error Resume Next
    Set swApp = GetObject(, "sldworks.application")
   
    If swApp Is Nothing Then
        Set swApp = CreateObject("SldWorks.Application")
        swApp.Visible = True
    Else
        If MsgBox("This macro is about to close all documents open in solidworks, without saving. If you would like to make changes to or save any of these files, press cancel and start the macro when you are ready. Otherwise, press ok.", vbOKCancel, "Continue?") = vbCancel Then
            Exit Sub
        End If
    End If
   
   
   
    Set swModel = swApp.OpenDoc6(strPart, swDocPART, swOpenDocOptions_slient, "", lErrors, lWarnings)
    partsaved = swModel.SaveAs4(NewFileOpenPath, swSaveAsCurrentVersion, swSaveAsOptions_Copy, lErrors, lWarnings)

    boolstatus = swApp.CloseAllDocuments(True)
   
    Set swModel = Nothing
    Set swModel = swApp.OpenDoc6(NewFileOpenPath, swDocPART, swOpenDocOptions_slient, "", lErrors, lWarnings)
    Set swModel = swApp.ActiveDoc

   
    swModel.ForceRebuild3 (False)
   
   
    Call changevar("length", fLength)
    Call changevar("width", fWidth)
    Call changevar("height", fHeight)
    Call changevar("pin_center_distance", pin_centers)


    'call changevar("rollover_trunion_state",rollover_trunion_state)
   
   
    MsgBox "You have created a f with the following dimensions:" & vbNewLine & "Length: " & fLength & vbNewLine & _
    "Width: " & fWidth & vbNewLine & _
    "Height: " & fHeight & vbNewLine & _
    "Pin Centers: " & pin_centers & vbNewLine & vbNewLine & _
    "It has been saved in the following location: " & vbNewLine & _
    savefilepath
   


End Sub

Sub changevar(VARIABLE_NAME As String, NEW_VALUE As Long)

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swEqnMgr = swModel.GetEquationMgr
   
    NEW_VALUE = CStr(NEW_VALUE)
    For i = 0 To swEqnMgr.GetCount - 1
        vSplit = Split(swEqnMgr.Equation(i), "=")
        vSplit(0) = Replace(vSplit(0), Chr(34), Empty)
       
        If vSplit(0) = VARIABLE_NAME Then _
            swEqnMgr.Equation(i) = Replace(swEqnMgr.Equation(i), vSplit(1), NEW_VALUE)
    Next i
End Sub


End Sub

I modified code that Keith Rice provided earlier to create the subroutine, credit goes to him.

SolidworksApi macros