Macro via Excel for STEP file saving with choice of name

Hi all

I've been doing a lot of work on the forum and I can't find an answer to my question.

So, via an Excel workbook I want to manage 2 dimensions of a SolidWorks part and then save it in STEP format in a predefined destination folder.

On the other hand, I want to be able to save my part in STEP by being able to give it the name I want or if possible take the field of an Excel cell to name it.

Here's the code I use:

Sub Bouton1_QuandClic()

Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Part.Parameter("H@Esquisse1"). SystemValue = Range("C3"). Value / 1000
Part.ClearSelection
Part.ForceRebuild
Part.Parameter("L@Esquisse1"). SystemValue = Range("C4"). Value / 1000
Part.ClearSelection
Part.ForceRebuild

' Save As
longstatus = Part.SaveAs3("C:\Users\bectarlu\OneDrive - CAMFIL AB\Desktop\Room Family\STEP_" & ActiveConfiguration & ". STEP", 0, 2)

End Sub

Thank you in advance for your help
Kind regards
Ludovic

Hello @Bec2 ,

A proposal that goes as simple as possible: place the path and the name of the file in an Excel cell (C5) and adapt it in the code with the name of the active configuration...
image

Option Explicit

Sub Bt1Clic()

Dim swApp      As Object
Dim Part       As Object
Dim longStatus As Long
Dim stepName   As String
    
    Set swApp = CreateObject("SldWorks.Application")
    Set Part = swApp.ActiveDoc
    Part.Parameter("H@Esquisse1").SystemValue = Range("C3").Value / 1000
    Part.Parameter("L@Esquisse1").SystemValue = Range("C4").Value / 1000
    Part.ClearSelection
    Part.ForceRebuild
    
        ' Save As Step
    stepName = Range("C5") & Part.getActiveConfiguration.Name & ".STEP"
    longStatus = Part.SaveAs3(stepName, 0, 2)

End Sub

Kind regards.

3 Likes