Hide Table of Contents

Close Document Example (VBA)

This example shows how to create new parts and close the parts by name.

 

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

Dim swApp As Object

Dim Part As Object

Dim Gtol As Object

Dim partTitle, partTitle2 As String

 

' This must be explicitly defined for ActivateDoc2

Dim errors As Long 

 

Sub OpenAndCloseDocs()

 

Set swApp = CreateObject ("SldWorks.Application")

 

' Open a new part

Set Part = swApp.NewPart    

' Get the part title

partTitle = Part.GetTitle    

' Example call using this Part object

Part.EditRebuild     

 

' Open another new part

Set Part = swApp.NewPart    

' Get the part title

partTitle2 = Part.GetTitle    

' Example call using this Part object

Part.EditRebuild     

 

' Release the Part pointer

Set Part = Nothing     

' Close the second part

swApp.CloseDoc partTitle2    

 

' Activate the original part

Set Part = swApp.ActivateDoc2 (partTitle,True,errors) 

If ((errors <> 0) or (Part is Nothing)) Then

SwApp.SendMsgToUser "Error activating document"

 

' <Based on the error, put desired code here.>

 

Exit Sub   

End If

 

' Example call using this Part object

Part.EditRebuild     

 

' You also have the option of using different object variable names for the PartDoc object (that is, Part1 and Part2) and performing PartDoc object (that is, Part1 and Part2) and performing operations on each PartDoc using the individual object variables. As a general practice, it is probably a good idea to make the desired PartDoc the active document (ActivateDoc2) when you will be performing operations with that document.

' For example:

' Dim Part1, Part2 As Object

' Set Part1 = swApp.NewPart

' Set Part2 = swApp.NewPart

 

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:   Close Document 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) 2014 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.