Hide Table of Contents

Add Buttons to Task Pane Example (VBA)

This example shows how to add standard SOLIDWORKS and custom buttons to the Task Pane.

' Preconditions:
' 1. Copy Main to the main module.
' 2. Click Insert > Class Module and copy Class to that module.
' 3. Copy save.png from public_documents\tutorial\api to
'    this macro 's folder.
' Postconditions:
' 1. Opens the Task Pane and loads the My Calendar control with 
'    the specified standard and custom buttons at the
'    top of the pane.
' 2. Click each button from left to right.
' 3. Displays a message box confirming each button click.
' 4. Click OK to close each message box.
'    a. Clicking the Close button prompts you to remove the
'       control from the Task Pane.
'    b. Click OK.
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swTaskPane As SldWorks.TaskpaneView
Dim result As Boolean
Dim folder As String
Dim bitmap As String
Dim toolTip As String
Dim ctrlName As String
Dim ctrlLicKey As String
Public buttonIdx As Integer
Dim swTaskpaneEvents As New Class1
Sub main()
    Set swApp = Application.SldWorks
    folder = swApp.GetCurrentMacroPathFolder + "\"
    ' Use default image for Task Pane tab
    bitmap = ""
    toolTip = "My Calendar"
    ctrlName = "My.Calendar"
    ctrlLicKey = ""
    Set swTaskPane = swApp.CreateTaskpaneView2(bitmap, toolTip)    
    ' Add standard and custom buttons to Task Pane
    result = swTaskPane.AddCustomButton(folder & "save.png", "Save (custom png)")
    result = swTaskPane.AddStandardButton(swTaskPaneBitmapsOptions_Next, "Next (standard)")
    result = swTaskPane.AddStandardButton(swTaskPaneBitmapsOptions_Back, "Back (standard)")
    result = swTaskPane.AddStandardButton(swTaskPaneBitmapsOptions_Ok, "OK (standard)")
    result = swTaskPane.AddStandardButton(swTaskPaneBitmapsOptions_Close, "Close (standard)")    
    ' Add control to Task Pane for the buttons
    swTaskPane.AddControl ctrlName, ctrlLicKey    
    ' Set up events
    Set swTaskpaneEvents.swTaskPane = swTaskPane
End Sub


Option Explicit
Public WithEvents swTaskPane As SldWorks.TaskpaneView
Private Function swTaskPane_TaskPaneActivateNotify() As Long
    If (swTaskPane.GetButtonState(0) = False) Then
        For buttonIdx = 0 To 20
            swTaskPane.SetButtonState(buttonIdx) = True
        For buttonIdx = 0 To 20
            swTaskPane.SetButtonState(buttonIdx) = False
    End If
End Function
Private Function swTaskPane_TaskPaneDestroyNotify() As Long
    MsgBox ("Remove control from Task Pane?")
End Function
Private Function swTaskPane_TaskPaneToolbarButtonClicked(ByVal ButtonIndex As Long) As Long
    Select Case (ButtonIndex + 1)
        Case 1
            MsgBox "Save (custom png) button clicked."
        Case 2
            MsgBox "Next button clicked."
        Case 3
            MsgBox "Back button clicked."
        Case 4
            MsgBox "Okay button clicked."
        Case 5
            MsgBox "Close button clicked."
    End Select    
End Function


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:   Add Buttons to Task Pane 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) 2017 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.