Hide Table of Contents

Save Part with New Name Example

This example shows how to load an existing SolidWorks part and save it with a new name.

 

'---------------------------------------------

Sub Main( )

 ' Define variable used to hold the ISldWorks object

 Dim swApp As Object

 ' Define variable used to hold the IModelDoc object

 Dim Model As Object

 ' This must be explicitly defined for ActivateDoc2

 Dim errors As Long

 

 ' Determine current directory

 MyPath = CurDir

 

 ' This attaches to the current SolidWorks session or starts up new session in background

 Set swApp = CreateObject("SldWorks.Application")

 

 ' Load file from current directory

 Set Model = swApp.OpenDoc(MyPath + "\Parametric.PRT", swDocPART)

 If Model Is Nothing Then

  Exit Sub

 ' If successful activate the document

 Else  

  Set Model= swApp.ActivateDoc2("Parametric.PRT", True, errors)

 End If

 ' Save the part with a new name

 newname = MyPath + "\FRED.PRT"

 

 ' Perform SaveAs and if it is successful

 If (Model.SaveAs(newname)) Then

  ' Define message

  Msg = "Part Saved As " + newname

  ' Button option shows OK only

  Style = vbOKOnly 

  Title = "Note!"   ' Define title.

  Call MsgBox(Msg, Style, Title)  ' Display message to user

 End If   ' End if SaveAs is successful

 

' Close the document

swApp.CloseDoc newname  

 

' Close the SolidWorks application. If you do not perform this step, SolidWorks continues to run. If SolidWorks is running in background, the user is unaware that SolidWorks is running and consuming their system resources.

swApp.ExitApp

End Sub

 

 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Save Part with New Name Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2012 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.