It’s time to add User Form to our Macro code, So that we don’t need to edit code to change specific values or actions.
First of all click on Edit Macro button in your macro toolbar and open your Circle Extrude code.
Go to Insert > UserForm (Click on it). This will insert new user form for our macro code.
So, We want to use this User form to change Extrude length of Circle created in Sketch.
So add Textbox , label and button to it from Toolbox as below.
So, Now nothing is functional in this User form if you run macro ‘F5’ then Run button will not work right now.
Go to our mail Macro code and Copy code inside Main subroutine.
Click on User Form and Double click on ‘Run’ button this will show code area.
Paste your copied code here and Edit as below , Add comments.
Now that we have added User form and pasted our code to create and extrude circle it’s time to change our mail code so that it will show this user form.
Double click on CircleExtrude1 module change code as beloow
We have early bind code here Remember our post Understand SolidWorks Macro Code ?
Now, Open blank part as pre requirement of our macro code.
Run macro (press F5). This will show User Form in SolidWorks. Type extrude length value and Press ‘Run’ button.
After execution this user form will not hide or end ?
We need to add code ‘End’ inside UserForm before ‘End Sub’