Hide Table of Contents

Move Annotations to First Annotation View Example (VBA)



' Preconditions:  Open document with at least two

'                 annotation views. Each view should have at

'                 least one annotation.


' Postconditions: Annotation and annotation view names

'                 printed to debug window. All annotations moved

'                 to the first annotation view.



Option Explicit


Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swModelExt As SldWorks.ModelDocExtension

Dim swAnnViews As Variant               'Array of annotation views

Dim vAnnotations As Variant             'Array of annotations

Dim vAnnToMove() As SldWorks.Annotation 'Collections of annotations to move

Dim swAnnView As SldWorks.AnnotationView

Dim i As Integer, j As Integer, k As Integer

Dim swAnn As SldWorks.Annotation

Dim boolstatus As Boolean


Sub main()


Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

Set swModelExt = swModel.Extension


ReDim vAnnToMove(0)


swAnnViews = swModelExt.AnnotationViews


'Activate each view; only one view can be active at a time

For i = 0 To swModelExt.AnnotationViewCount - 1

    Set swAnnView = swAnnViews(i)

    Debug.Print "Annotation view name: " & swAnnView.Name


    'Alternative to activate




'Print each annotation name and add all annotations to a collection

For i = 0 To swModelExt.AnnotationViewCount - 1

    Set swAnnView = swAnnViews(i)


    vAnnotations = swAnnView.Annotations

    If Not IsEmpty(vAnnotations) Then

        For j = 0 To UBound(vAnnotations)

            Set swAnn = vAnnotations(j)

            Set vAnnToMove(UBound(vAnnToMove)) = swAnn

            ReDim Preserve vAnnToMove(UBound(vAnnToMove))

            Debug.Print "Annotation name: " & swAnn.GetName



    End If


    'Move all annotations to first annotation view

    If i > 0 Then

        Set swAnnView = swAnnViews(i)

        boolstatus = swAnnView.MoveAnnotations(vAnnToMove)

        Debug.Assert boolstatus

    End If


    ReDim vAnnToMove(0)



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

Subject:   Feedback on Help Topics
Page:   Move Annotations to First Annotation View Example (VBA)
*   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:


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

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.