SOLIDWORKS Macros Repository Under Maintenance
The VBA and C# Macros Automation Library is currently disabled while step-by-step execution guides are being compiled. This tool will be re-enabled soon!
Interactive SOLIDWORKS VBA Scripts Repository
Select a macro tab to view the source, copy the script, or download the binary project file.
Saves the active configuration of an open Assembly (.SLDASM) document as a separate native SOLIDWORKS Part (.SLDPRT) sheet in a specified output folder.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim vConfigNames As Variant
Dim sConfigName As String
Dim sAssyPath As String
Dim sFolderPath As String
Dim sAssyName As String
Dim sSavePath As String
Dim i As Integer
Sub SaveConfigsAsParts()
' Get SolidWorks Application
Set swApp = Application.SldWorks
' Get Active Document
Set swModel = swApp.ActiveDoc
' Check if a document is open
If swModel Is Nothing Then
MsgBox "No document is open. Please open an assembly file and try again.", vbExclamation, "Error"
Exit Sub
End If
' Check if the active document is an assembly
If swModel.GetType <> swDocASSEMBLY Then
MsgBox "This macro only works with assemblies. Please open an assembly file.", vbExclamation, "Error"
Exit Sub
End If
' Ask user where to save the files
sFolderPath = InputBox("Enter the folder path to save part files:", "Select Save Location")
' Ensure folder path ends with a backslash
If Right(sFolderPath, 1) <> "" Then sFolderPath = sFolderPath & ""
' Get Assembly Name and Path
sAssyPath = swModel.GetPathName
sAssyName = Mid(sAssyPath, InStrRev(sAssyPath, "") + 1) ' Extract File Name
sAssyName = Left(sAssyName, InStrRev(sAssyName, ".") - 1) ' Remove Extension
' Get All Configurations
vConfigNames = swModel.GetConfigurationNames
' If no configurations, exit
If IsEmpty(vConfigNames) Then
MsgBox "No configurations found!", vbExclamation, "Error"
Exit Sub
End If
' Loop through each configuration
For i = 0 To UBound(vConfigNames)
sConfigName = vConfigNames(i)
' Activate the configuration
swModel.ShowConfiguration2 sConfigName
' Define Save Path
If sConfigName = "Default" Then
sSavePath = sFolderPath & sAssyName & ".SLDPRT"
Else
sSavePath = sFolderPath & sConfigName & ".SLDPRT"
End If
' Save as Part File
swModel.SaveAs sSavePath
Debug.Print "Configuration '" & sConfigName & "' saved as Part at: " & sSavePath
Next i
' Done
MsgBox "All configurations saved successfully in: " & sFolderPath, vbInformation, "Completed"
End Sub⚙️ How to Load & Run VBA Macros in SOLIDWORKS
Follow this step-by-step visual configuration wizard to execute downloaded macro files inside SOLIDWORKS.
Step 1: Open SOLIDWORKS Macro Tool
Launch SOLIDWORKS. On the main top application toolbar dropdown, select "Tools" -> "Macro" -> "Run...".
