Linking a macro to a command button


Board Regular
Jul 28, 2006
I am a total Newbie when it comes to VBA. How to you link a macro to a command button.

I have a series of macros that have Ctrl + letters shortcuts, but I thought it would be easier jyst to have a have a button to push.

Also, can anybody recommend a good book for getting started with VBA?

Thank you for your help.

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Joe Was

MrExcel MVP
Feb 19, 2002
Excel ToolBar: View - ToolBars - Forms, then drag the button to your sheet. You can re-position later. It will ask you for the macro to run, so it needs to be built first!
Right click "Format Control" to edit font color and text.

Excel ToolBar: View - ToolBars - Controls, drag...
This button when Right-Clicked has the "view code" option which goes to the click event for that button. These buttons have much more flexability and the button colors can be changed, unlike the Form button.

The next button type is from the shapes menu.
Excel ToolBar: View - ToolBars - Drawing, additional shapes "Bevel" this is a 3-D button much like the Control Button.

The best way to learn to code is to look for someting that you need on this board using the Search utility. Then try to improve it, add more to it, make it do different things. When you get into a problem doing so, post the problem. This way you are learning the things you need to work with and what you work with. Most books are too general and cover things you will never use so you will get weighed down with things that are hard to remember and that will confuse you on the things you do use.

This site has books that have helped many people.

You can get there above at the "Online Store" or:


Well-known Member
Jun 19, 2003
If it is a Control Toolbar object, select Design mode on the Control Toolbar to work with the button. Double click the button to open VBA to assign code.
Setup the Button's Click event to call your macro, like this:
Private Sub CommandButton1_Click()
  Call MacroName
End Sub
Change "MacroName" to the name of your macro.

Watch MrExcel Video

Forum statistics

Latest member