Recording and Playing Macros

Macros are scripts that let you run operations in the SOLIDWORKS software automatically.

You can create a macro and program it outside of the SOLIDWORKS software, or you can record a macro that captures a sequence of actions and commands as you perform them in the SOLIDWORKS software.

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

You can also create a macro customization that lets you run a macro from its own toolbar button or with a keyboard shortcut or mouse gesture.

New Macro

You can create a new macro from the Macro toolbar or the Tools menu and then program the macro in a macro editing application.

Creating a new macro is different from recording a macro. When you create a new macro, you program the macro directly from a macro editing application such as Microsoft Visual Basic. When you record a macro, you create the macro from within the SOLIDWORKS software.

To create a new macro:

  1. Click New Macro Tool_New_Macro.gif (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

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

A macro contains the equivalent calls to the API functions that were made when the operations were performed with the user interface. A macro can record your mouse clicks, menu choices, and keystrokes to play back later.

You can also create a new macro without recording one first.

To record a macro:

  1. Click Record/Pause Macro Tool_Record_Pause_Macro.gif (Macro toolbar) or Tools > Macro > Record.
  2. Perform the steps you want to record.
    To pause while recording a macro, click Record/Pause Macro Tool_Record_Pause_Macro.gif (Macro toolbar) or Tools > Macro > Record . Click Record/Pause Macro Tool_Record_Pause_Macro.gif again to continue recording.
  3. When you are done, click Stop Macro tool_Stop_Macro.gif (Macro toolbar), or click Tools > Macro > Stop.
  4. In the dialog box, type a name for File name and click Save. (The .swp extension is automatically added to the filename.)

Run Macro

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

To run a macro:

  1. Click Run Macro (Macro toolbar) or Tools > Macro > Run.
  2. In the dialog box, locate a macro file (*.swp, *.swb) and click Open.
    If the macro contains more than one function or subroutine, the last subroutine with no arguments in the module most recently created in the VBA project runs.

Edit Macro

You can edit or debug a macro that you recorded previously.

To edit a macro:

  1. Click Edit Macro tool_Edit_Macro.gif (Macro toolbar) or Tools > Macro > Edit.
    If you have previously edited macros, you can select the macro directly from the menu when you click Tools > Macro. This menu lists the last nine edited macros.
  2. In the dialog box, select a macro file (.swp) and click Open.
    You can also edit .swb files. When you run or edit an .swb file, it is automatically converted to a .swp file.
  3. Edit the macro. (For details, use the help in the macro editor.)

VBA

Visual Basic for Applications (VBA) is the engine that records, runs, or edits macros in SOLIDWORKS. Recorded macros are saved as .swp VBA project files.

You can read and edit .swb and .swp (VBA) files with the VBA editor. When you edit an existing .swb file, the file automatically converts into a .swp file. You can export a module to a file that you can use in other VB projects.

You can use VBA to create forms and to provide more user interaction with your recorded macros. For more information on VBA, see the Help menu in the VBA editor.

Macro Feature Files

Macro feature files create application-defined features that you can add to a SOLIDWORKS model. Their effect on the model is defined by custom programs that you or a third-party software developer supplies.

For more information on macro feature files, see the SOLIDWORKS API Help.