VBA SOLIDWORK

Get the name of the currently open file

ToolBOX01 2024. 12. 30. 10:34

This is the code to get the active model name in solidworks

Dim swApp As SldWorks.SldWorks
Dim swModel As ModelDoc2
Sub SolidworksStart()
    On Error Resume Next
    '// Setting up SolidWorks application objects
    Set swApp = GetObject(, "SldWorks.Application")

    On Error GoTo 0
    If swApp Is Nothing Then
        MsgBox "Make sure SolidWorks is running.", vbCritical
        Exit Sub
    End If

    '// Get currently active document
    Set swModel = swApp.ActiveDoc
    If swModel Is Nothing Then
        MsgBox "There are no active SolidWorks documents.", vbCritical
        Exit Sub
    End If
    
    Msgbox  swModel.GetTitle

End Sub