Linking a macro to a command button

sdurocher

Board Regular
Joined
Jul 28, 2006
Messages
93
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.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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:

http://www.mrexcel.com/sunshop/index.php?action=&id=&subid=
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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