{"id":4602,"date":"2016-04-21T14:01:07","date_gmt":"2016-04-21T14:01:07","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/wp\/?p=4602"},"modified":"2022-08-12T11:40:38","modified_gmt":"2022-08-12T11:40:38","slug":"link-macro-to-a-command-button","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2016\/04\/link-macro-to-a-command-button\/","title":{"rendered":"VBA Beginners: How to write macro for a Command Button"},"content":{"rendered":"
Dear Beginners,<\/p>\n
Quite a few times I was getting this question from my readers – <\/p>\n
Note:<\/strong> These steps are common for all the ActiveX Controls added in excel sheet like Text box, Radio Button, Check box etc.<\/i><\/p>\n Add your command button as shown in below picture: Add Button in Excel<\/p><\/div><\/p>\n Double click on the Button (note: Before double clicking make sure that you are in design mode in excel macro as highlighted above) Add code for Command Button<\/p><\/div><\/p>\n You can right click on the command button and click on “View Code” as well View code of Command Button<\/p><\/div><\/p>\n By default you will be taken to a screen as shown below. Click Event for Button<\/p><\/div> There between “Sub” and “End Sub” you can write your own code or you call call any other function which you have already defined.<\/p>\n Dear Beginners, Quite a few times I was getting this question from my readers – How to associate a VBA code to a button? How to write a vba code which gets executed by clicking on a command button in excel vba. Add a button to trigger my macro and so on… Here are 3 […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1674,1679,1675],"tags":[],"class_list":["post-4602","post","type-post","status-publish","format-standard","hentry","category-excel-macro-basics","category-excel-macro-beginner","category-excel-macro-for-beginners"],"yoast_head":"\nStep 1: <\/h2>\n
\nStep 2:<\/h2>\n
\nOR<\/h3>\n
\nStep 3:<\/h2>\n
\n
\n
\nIn the above image as you can see in the right hand side there is a drop down which has all the events which can be triggered on this commandbutton like .”Click”, Double Click”, on focus etc. As you as select an event VBA screen will automatically take you to that event procedure syntax. <\/p>\nNote: The above 3 steps can be done for any of the ActiveX Controls added in your excel sheet. Like, Text Box, Radio Button, Check box etc.<\/h2>\n
Provide your feedback if you like this simple and crisp information<\/h2>\n<\/span>","protected":false},"excerpt":{"rendered":"