VBA In Solidworks

2 minute read

Solidworks provides us two methods for open Visual Basic for Application.

  1. Menu based method
  2. Toolbar method

Please see below video for visual details.

To open VBA window, go Tools in menu bar. Then go to Macro. When you click Macro you found 5 options or button. (Menu bar -> Tool -> Macro)

Use below images for better help.

Click Tools as show below.

menu_option-1

Click Macro as show below.

menu_option-2

After clicking Macro below options appears

menu_option-3

Description and working of each button will be given after next method.

Toolbar method

To open VBA window, click Right Mouse Button anywhere in screen.

By doing this a list of all available Toolbar option appears. In this list, we need to select Macro toolbar to show macro toolbar.

Use below images for better help.

After clicking of Right Mouse Button below Toolbar list appears.

tool_bar_option-1

From this list we need to select Macro option as show below.

tool_bar_option-2

After clicking “Macro” option below toolbar appears.

tool_bar_option-3

This option includes same buttons as described in Menu based method.

Description and Functions of each button is given below.

New Macro Button new_macro_button-3

You can create a new macro by this button and then program the macro in VBA.

Creating a macro is different from recording a macro. When you create a new macro, you program the macro directly from a editing application such as Visual Basic Editor.

When you record a macro, you create the macro within the Solidworks software.

To create a new macro:

  1. Click New Macro new_macro_button-3 (Macro toolbar), or click Tools -> Macro -> New.

  2. Type a file name.

  3. Click Save

Your macro editing application opens ready for you to program the new macro.

Record/Pause Macro Button record_pause_macro_button-3

You can record operations performed with the Solidworks user interface and replay them with Solidworks macros.

A macro contains equivalent API functions. These API functions were made when the operation were performed with the user interface.

A macro can record your mouse clicks, menu choices and keystrokes to play back later.

To record a macro:

  1. Click Record/Pause Macro Button record_pause_macro_button-3 (Macro toolbar), or click Tools -> Macro -> Record.

  2. Perform the steps you want to record.

  3. When you are done, click Stop Macro Button stop_macro_button-3 (Macro toolbar), or click Tools -> Macro -> Stop.

In the dialog box, type a name for File name and click Save. (The .swp extension is automatically added to the filename.)

Run Macro Button run_macro_button

You can run macro from the Macro toolbar or Tools menu.

To run a macro:

  • Click Run Macro Button run_macro_button (Macro toolbar), or click Tools -> Macro -> Run.

  • In the dialog box, locate a macro file (.swp, .swb) and click Open.

Edit Macro Button edit_macro_button

You can edit macro from the Macro toolbar or Tools menu.

To run a macro:

  • Click Edit Macro Button edit_macro_button (Macro toolbar), or click Tools -> Macro -> Edit.

  • In the dialog box, locate a macro file (.swp, .swb) and click Open.

  • Edit the macro.

Next post will be about Open new Part document using Solidworks macros.

Updated: