Command Button Confusion

teachman

Active Member
Joined
Aug 31, 2011
Messages
321
Hello,

I want a command button on a worksheet that calls an error checking macro. Since I use this error check macro on more than one worksheet I put the code in a module, rather than duplicate the code in each worksheet.

I'm using Excel 2007 and there are two ways to create the command button. Form Controls and ActiveX Form Controls. I'd like to spruce up the button, at least with a color different than gray. So, I used the ActiveX form control Command Button. I did spruce it up a bit, but then I can't link it to my error checking macro, which I put in a module. If I use an old fashioned Form Control Command Button, I can link it to the macro in the module but I can't spruce the button up.

Normally, I'm a function over form kind of guy, but in this case I'd like a little more form with the same function.

The question is how can I link the macro code in a module to an ActiveX Command Button?

Thanks for your help.

George Teachman
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Something like this

Code:
Private Sub CommandButton1_Click()
Call mymacro
End Sub
 
Upvote 0
VoG or Peter (not sure which)

I tried that and I was rewarded with 'Compile error; Expected procedure, not variable.'

I was using:

Code:
Sub ErrorCheck_Click()
Call ErrorCheck
End Sub

That's when I noticed that I was calling the ErrorCheck macro in a module from a macro called ErrorCheck_Click. I got to wondering if I was confusing VBA. Lord knows, it's confused me often enough. Anyway, I renamed my macro in the module to ErrorCheck2 (I'm nothing if not persistent) and changed the above code to:

Code:
Sub ErrorCheck_Click()
Call ErrorCheck2
End Sub

Now it works.

Thanks for your help.

George



Something like this

Code:
Private Sub CommandButton1_Click()
Call mymacro
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,381
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top