VBA Macro Issue for Solidworks

Good evening

 

I'm a big novice in VBA.

 

I'm trying to develop a macro that allows you to open a dialog box in which you can change the length and height of a railing.

Well until the opening of the macro it works pretty well but as soon as it comes to modify the dimension values in the sketch..... big snag.

 

It sends me back a '91' execution error.... a classic it seems..;)

 

I can't find the solution.

 

I am attaching the document and the macro.

 

Thank you in advance for your help!


garde-corps_test.zip

Hello

 

as some people would say, ask "Lucas Prieur" for help, he knows very well about macro!!

5 Likes

or @jfaradon, it works too!

3 Likes

Hello

 

In fact, the "UserForm_activate" event is never called... so swDoc is tjrs nothing

 

Replace "UserForm_activate" with  "UserForm_Initialize"

and it will work much better...

 

7 Likes

I put the modified macro back


garde-corps_test.zip
5 Likes

I wasn't the fastest on this one!

1 Like

Hi everyone

 

thank you very much for your help and especially to you Jfaradon! It works with God's fire, if I may say so.

 

Well and if I can abuse it........ I was wondering if there was a possibility that this dialog box would automatically appear when I insert my part into an assembly?

 

Thank you

to do this kind of automation, it's more complicated, you have to make a SW add-in that manages the events of the application. In fact, you have to program more than a macro, you have to go through a development tool like Microsoft Visual Studio.

 

There is a myCAD tool for this called CustomToolBar, in which it is possible to trigger a macro in relation to events (insertion of a component for example)

But simpler without this tool is to create a macro shortcut in the toolbars.

 

2 Likes