Saturday 14 April 2018

Visual Basic in SOLIDWORKS

Visual Basic in SOLIDWORKS

SOLIDWORKS provides us two methods for open Visual Basic for Application.
  1. Menu based method
  2. Toolbar method

Menu Base Method

To open VBA window, go "Tools" in the menu bar. Then go to "Macro". When you click "Macro" you found 5 options or button. (Menu bar ⇨ Tool ⇨ Macro)
Use following images for better help.
  1. Click "Tools" as shown below.

    Tool button in menu bar
  2. Click "Macro" as shown below.

    Macro option list in menu bar
after clicking "Macro" below option appears

Macro menu options

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

Toolbar Method

To open VBA window, click “Right Mouse Button” anywhere on the screen. By doing this a list of all available "Toolbar" option appears. In this list, we need to select "Macro" toolbar to show the macro toolbar.

After clicking of Right Mouse Button below Toolbar list appears.

Toolbar list

From this list, we need to select "Macro" option as shown below.

Select macro option from Toolbar list

After clicking "Macro" option below toolbar appears.

Macro Toolbar

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

Description and Functions of each button are given below.

New Macro Button New Macro Button

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 an 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
    (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

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 was 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 (Macro toolbar), or click Tools ⇨ Macro ⇨ Record.
  2. Perform the steps you want to record.
  3. When you are done, click Stop Macro Record/Pause Macro Button (Macro toolbar), or click Tools ⇨ Macro ⇨ Stop.
  4. In the dialog box, type a name for the File and click Save. (The “.swp” extension is automatically added to the filename.)

Run Macro Button Stop Macro Button 

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

To run a macro:

  1. Click Run Macro Button Run Macro Button (Macro toolbar), or click Tools ⇨ Macro ⇨ Run.
  2. In the dialog box, locate a macro file (*.swp, *.swb) and click Open.

Edit Macro Button Run Macro Button 

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

To Edit a macro:

  1. Click Edit Macro ButtonRun Macro Button (Macro toolbar), or click Tools ⇨ Macro ⇨ Edit.
  2. In the dialog box, locate a macro file (*.swp, *.swb) and click Open.
  3. Edit the macro.

    No comments:

    Post a Comment