MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Starting a macro from a userform command button


Posted by richard on January 18, 2002 5:50 AM

I am trying to create a userform which will contain several buttons (each of which will trigger a different macro routine). Anyone know how I can do this (or suggest an altervative methd that would do the same?). Some cose would be greatly appreciated as I'm still a beginner with VB. Thanks


Posted by Michael on January 18, 2002 6:40 AM

If you create your buttons on the userform by using the Forms Toolbar, you can assign the macro directly to the button. The easiest way to create the macros that you want is to record them. When you record them, you assign a name and a shortcutkey, perform the function that you want and then stop the recording. At that point you can assign the macro to the button that you create with the Forms Toolbar. If you need something more than this, just drop another line on the Forum.

Posted by richard on January 18, 2002 7:08 AM

Thanks - I tried that first but I cannot find the forms toolbar when I go into VB. The only toolbar options are Debug, Edit, Standard and UserForm - are you sure this is possible?


Posted by Michael on January 18, 2002 10:05 AM

Sorry, I misunderstood you. THe buttons you are looking for are located on the toolbox that comes ub when you select the user form option under insert.

Now, the problem with this is that these are active x controls (meaning that each one will have the code specifically for them). Right click on the button after you placed it on the sheet and you will see that View Code option. If you select this, a sheet will come up for the sub that you want to create.