Calling a macro via a userform

Hello

Having several macros I would like to make a clean layout in order to choose the appropriate macros. So I created a macro that opens a userform containing different buttons. I would like to open my different macros via these buttons. The problem is that I have no idea how to use them.

I tried with this:

Private Sub CommandButton2_Click()
Dim swApp As SldWorks.SldWorks

Set swApp = Application.SldWorks
    
RunMacro "\\***-srv-fic-01.******.local\OneDrive$\_Solidworks resources\Templates ******\Macro.swp", "Macro", "main"
    

Sub RunMacro(path As String, moduleName As String, procName As String)
swApp.RunMacro2 path, moduleName, procName, swRunMacroOption_e.swRunMacroUnloadAfterRun, 0
End Sub
End Sub

Unfortunately it doesn't work. Anyone have an idea? Maybe with the Call function (I tried but didn't work, I may have coded the function incorrectly)

Thank you

Kind regards

To call a macro:

https://www.codestack.net/solidworks-api/application/frame/run-macros-group/

Otherwise you can maybe use Customtoolbar in the Visiativ tools which allows you to create a menu with all the macros + icon:

https://help.visiativ.com/mycadtools/2020/fr/CustomToolBar.html

Thank you for the answer 

The code on codestack I know it, it's even the one I used as an example but it doesn't work for the button of a userform. 

For mycadtools, I'm not against it but my company is not going to invest right away, that's why I developed some macros to automate certain processes. And that's why I want to make a clean layout so that it's nice and clear.

Kind regards

For Mycadtools tools, you normally have access to them since in your profile we see that you are subscribed to Mycadservice.

For the code from the userform, have you tried with a macro stored from a more traditional drive? (e.g. c:\Temp\Macro.swp)

I've tried but it doesn't work either. I'm still looking but I'm making knots in my brain. I double-checked on Code stack but there is nothing either.

There would be the solution to program all the macros in each button of the userform but it's almost impossible because I have an incalculable number of variables, there's nothing better than that to make mistakes.

That's where I am, if anyone wants to add their stone to the edifice they are welcome.

Thank you

Kind regards 

Hello

See attached macros. You have to put macro1, macro2 and macro3 in the "C:\temp\" folder and then run the macro "MacroLaunchViaUserForm.swp"

Kind regards


macrolaunchingviauserform.swp
macro1.swp
macro2.swp
macro3.swp
2 Likes

Hello

A silly question; But why not put your macros in the "macro" bar with beautiful icons to know their uses.

https://www.lynkoa.com/forum/2d/creer-un-bouton-macro

1 Like

Or right-click on a command bar==>custom==>command==> then you type macro and you grab the last icon and you drag and drop it into the bar and you  follow the instructions...

1 Like

@d.roger It's great thank you, I've been in front of it so many times, it was so simple. It works wonderfully, thank you again.

@ac cobra 427 Indeed it was the idea at the beginning, but I have 8 macros for now and maybe more later. So overriding the command bar is not the best option either, hence my desire to create a userform that groups all the buttons, so that a simple button in the command bar is necessary.

Thanks again to you and have a good day.

Kind regards   

1 Like