VBA In Solidworks
Solidworks provides us two methods for open Visual Basic for Application.
- Menu based method
- Toolbar method
Please see below video for visual details.
Menu Base Method
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.
Click Macro
as show below.
After clicking Macro
below options
appears
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.
From this list we need to select Macro
option as show below.
After clicking “Macro” option below toolbar appears.
This option includes same buttons as described in Menu based method
.
Description and Functions of each button is given below.
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 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:
-
Click New Macro (Macro toolbar), or click Tools -> Macro -> New.
-
Type a file name.
-
Click Save
Your macro editing application opens ready for you to program the new macro.
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
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:
-
Click Record/Pause Macro Button (Macro toolbar), or click Tools -> Macro -> Record.
-
Perform the steps you want to record.
-
When you are done, click Stop Macro Button (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
You can run macro
from the Macro
toolbar or Tools menu.
To run a macro:
-
Click
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
You can edit macro
from the Macro
toolbar or Tools menu.
To run a macro:
-
Click
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.