Hide Table of Contents

SolidWorks Macros

The quickest and easiest way to start programming with the SolidWorks API is to record a SolidWorks macro, which contains the SolidWorks API calls that correspond to the actions performed in the user interface. You can modify the macro in Microsoft Visual Basic for Applications (VBA) or Microsoft Visual Studio Tools for Applications (VSTA) to fit your work site's needs.

  • Microsoft VBA is a toolset based on Microsoft Visual Basic for Applications (VBA) and is embedded in the SolidWorks software. Microsoft VBA lets you record, run, and edit Microsoft VBA macros in the SolidWorks software. Recorded macros are saved as .swp files.

  • Microsoft VSTA is a toolset based on Microsoft VB.NET and C# and is embedded in the SolidWorks software. Microsoft VSTA lets you record, run, and edit VB.NET and C# code in the SolidWorks software. Recorded Microsoft VSTA macros are saved as either Microsoft VB.NET or C# projects. Building or debugging a Microsoft VSTA macro creates an executable file that ends in the filename extension .dll, which can be used by the SolidWorks software in the same manner as a .swp file.


    • VSTA Requires Microsoft .NET Framework 3.5.
    • When debugging Microsoft VSTA macros with user-interface components such as PropertyManager pages, manipulators, or other objects that use events or handler objects, the debugger must continue to run after the main() method of the VSTA macro exits. Either deselect the user-interface system option Stop VSTA debugger on macro exit (located on the Tools > Options > System Options dialog) or set swUserPreferenceToggle_e.swStopDebuggingVstaOnExit to false to keep the debugger running after the main() method of the Microsoft VSTA macro exits.

Typically you would follow these steps to create a SolidWorks API application using SolidWorks macros:

  1. Plan the user-interface actions before recording them.

  2. Record the user-interface actions.

    If you are not familiar with recording SolidWorks macros, record the macro a couple of times to eliminate interactive changes to the view such as changing the view orientation, zooming in or out, panning, rotating the model, and so on.

  3. Edit the macro to delete extra lines of code and explicitly declare and early bind variables.

  4. Run the macro to test it.

  5. Debug the macro and test it again.

  6. If the application has a user interface, create it in Microsoft VBA or Microsoft VSTA and then modify the macro to work with the user interface, run the modified macro, and debug it.

When done recording, testing, and debugging the macro, you can assign the macro to button.



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:   SolidWorks Macros
*   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) 2013 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.