Hide Table of Contents

Delete OLE Objects from Drawing Sheet and Template Example (VBA)

This example shows how to delete any OLE objects from the current drawing sheet and template.

'---------------------------------------------------------
' Preconditions: 
' 1. Open a drawing that contains one or more
'    OLE objects in the drawing sheet or template.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Deletes all OLE objects in drawing sheet
'    and template.
' 2. Examine the graphics area and Immediate window.
'--------------------------------------------------------

Option Explicit

Sub DeleteAllOleItemsInSheet _

( _

    swApp As SldWorks.SldWorks, _

    swModel As SldWorks.ModelDoc2, _

    swSheet As SldWorks.Sheet _

)

    Dim nOleCnt                     As Long

    Dim i                           As Long

    Dim nSize                       As Long

    Dim nAspect                     As Long

    Dim skArray()                   As Variant

    Dim bRet                        As Boolean

    nOleCnt = swSheet.GetOLEObjectCount: If 0 = nOleCnt Then Exit Sub

    ReDim skArray(nOleCnt - 1)

    

    ' Get location of each OLE item

    For i = 0 To nOleCnt - 1

        skArray(i) = swSheet.GetOLEObjectSettings(i, nSize, nAspect)

    Next i

        

    ' Delete each OLE items

    For i = 0 To nOleCnt - 1

        bRet = swModel.SelectByID("", "OLEITEM",0.5 * (skArray(i)(0) + skArray(i)(3)), 0.5 * (skArray(i)(1) + skArray(i)(4)), 0.5 * (skArray(i)(2) + skArray(i)(5)))

        bRet = swModel.DeleteSelection(False)
        Debug.Print ("OLE item " & i & " deleted? " & bRet)

    Next i

End Sub

 

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swDraw                      As SldWorks.DrawingDoc

    Dim swSheet                     As Object
 

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swDraw = swModel

    Set swSheet = swDraw.GetCurrentSheet    

    

    DeleteAllOleItemsInSheet swApp, swModel, swSheet

    

    ' Switch to template and delete OLE objects

    swDraw.EditTemplate

    Set swSheet = swDraw.GetCurrentSheet

    DeleteAllOleItemsInSheet swApp, swModel, swSheet

    

    swDraw.EditSheet    

    

    ' Switch back to sheet and make sure all OLE objects are deleted

    Set swSheet = swDraw.GetCurrentSheet

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:   Delete OLE Objects from Drawing Sheet and Template 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) 2019 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.