Creating Macro Buttons in SOLIDWORKS

Article by Prasadh Annalingam, CSWE updated October 7, 2020


In this tech tip, learn how to create and add SOLIDWORKS Macro Buttons to your toolbars along with creating a new Macro from scratch. If you would like to learn how to record a Macro and assign shortcuts then read our tech tip: Recording Custom Macros and Assigning Shortcuts in SOLIDWORKS

WARNING: Always test a Macro to ensure it is working correctly before implementing.

Follow these steps and you’ll have your very own custom Macro Button ready to use. If you are going to copy & paste code for a Macro or going to type it up yourself, please start at Step 1. If you already have an existing Macro (.swp) file, you can jump straight to Step 4.

Step 1:

Create a new Macro file. Go to Tools > Macro > New

SOLIDWORKS Tools Open New Macro

Create New Macro File

Step 2:

Choose where to save the new Macro with an appropriate file name


Save As: Find appropriate location and name

Step 3:

You will now see the default code for a new Macro open in the Microsoft Visual Basic for Applications Editor (VBA Editor). Add/replace the Macro code as required. Once completed make sure to click save and then close the window. You can always edit existing Macros by going to Tools > Macro > Edit.


Microsoft Visual Basic for Applications (VBA) Editor

Step 4:

We are now ready to create a new button for this Macro. Go to Tools > Customize or Quick Access Options > Customize. Please note, that a SOLIDWORKS Part, Assembly or Drawing must be open to be able to open the Customize option.

SOLIDWORKS Tools Customize

Open Customize Window

Step 5:

Go to the Commands Tab, select Macro in the list and find the New Macro Button as seen below.

New Macro Button

Find New Macro Button

Step 6:

Click and drag this icon to where you would like this Macro button placed in your SOLIDWORKS toolbar. For example, if you want this available in Command Manager or Quick Access Toolbar, drag them to the desired location as seen below. Please note for the rest of this example, 2 buttons will be added for demonstration purposes only. You only need to add it to 1 location, where you need it.

New Macro Button on Toolbar

Drag New Macro Button to Toolbar

Step 7:

The Customize Macro Button dialog will open. Find the desired Macro by selecting the three dots. Change the Tooltip name if desired and then select OK. The Tooltip name is what shows when you hover your mouse over the Macro button.
Advanced note: If the Macro has multiple methods/functions, please select which method you want the Macro to start first.

Customize Macro Button

Customize Macro Button

Step 8:

You now have the Macro Button added to your toolbar. The last step we must always do is test that it works correctly and DONE!

New Macro Button added to Toolbar

New Macro Button added to Toolbar

If you would like to Remove or Edit SOLIDWORKS Macro Buttons please click HERE to find how.


As you can see above, the Macro button has a generic icon image. If you want to apply a unique image for the Macro button, click “Choose Image” under “Appearance” in Step7. SOLIDWORKS provides bitmap images to use for custom buttons which can be found in install_dir\data\user macro icons.

(Eg. C:\Program Files\SOLIDWORKS 2020\SOLIDWORKS\data\user macro icons)

You can also create your own bitmap images that are 16×16 pixels, 256 colours, and with a white background.

Learn more about SOLIDWORKS Macros/API

You can learn more about how to create SOLIDWORKS toolbars in the SOLIDWORKS API Help as well as the training Javelin provides, SOLIDWORKS VB for Applications and SOLIDWORKS API training courses, which you can take live online. Check our training schedule to learn more.

Related Links

Certified SOLIDWORKS Services available from Javelin

Javelin can help you to:

Prasadh Annalingam, CSWE

Prasadh is a Certified SOLIDWORKS Expert and Technical Applications Analyst based in the Javelin Oakville head office.