AnsweredAssumed Answered

Needing help with VBA macro

Question asked by Mark Evans on Jun 27, 2017
Latest reply on Jun 28, 2017 by Mark Evans

Hello,

I have a solidworks part (a tube) which has 24 different length configurations. I am needing to save a parasolid file and a step file of each configuration to a folder of my designation. I wrote a macro that will do this for the active configuration, but when I manually switch to the next configuration and run the macro again, it will save the parasolid/step files with the previously defined file names.

 

Can someone give me some insight in how to correct this? Ideally, I'd like the macro to save the new parasolid/step files using the name of the specific active configuration with a -001 extension. Or...being able to manually input a name would be fine also. I'm looking to replace 1273262 in the text below with the active configuration name and then add on the -001 suffix.

 

I'm not a VBA user at all...but by macro code that I have developed so far is shown below.

 

' ******************************************************************************
' C:\Users\maevans\AppData\Local\Temp\swx12672\Macro1.swb - macro recorded on 06/27/17 by maevans
' ******************************************************************************
Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
Dim myModelView As Object
Set myModelView = Part.ActiveView
myModelView.FrameState = swWindowState_e.swWindowMaximized

' Save As
longstatus = Part.SaveAs3("C:\Users\maevans\Desktop\Tubes-CAD\1273262-001.x_t", 0, 0)

' Save As
longstatus = Part.SaveAs3("C:\Users\maevans\Desktop\Tubes-CAD\1273262-001.STEP", 0, 0)
End Sub

Outcomes