Assign a Hot Key to a Command Button in Excel
In Excel VBA you can assign a hot key for a command Button as well. It means you can assign a hot key to a command button which can be triggered by pressing that hot key from the keyboard. It means you can perform the operation either by clicking on the command button or by pressing the hot key.
For a command button you can assign a hot key by providing the key code in the Accelerator property of the command button. Accelerator property excepts a single key as an input from the keyboard. Hot key for a command button is always a combination of ALT key and the key entered by your choice.
Note: Interesting thing about setting a hot key (Accelerator property) for a command button is that you can easily find out the hot key associated for that command button, if your key (letter) exists in the caption of the command button. If key entered by you for a command button exists in the caption of the command button then automatically that letter from the caption get underlined. Refer the below image..
As highlighted in the above code, letter m is underlined because accelerator property is set to letter m, isn’t it interesting??
Now after setting up this property as soon as you press ALT + m from the keyboard CommandButton1 will be triggered and all the statements will be executed which is written for that command button.
My name is Vishwamitra Mishra. Friends Call me Vishwa. This blog is authored by me. I am an Excel Geek. Well, this blog talks a lot about my passion in Excels & Macros so I’ll not talk about it :) I am very much passionate about traveling & quite recently discovered that I am a good photographer too..:P
AND GET A FREE!
E-BOOK FOR EXCEL VBA BEGINNERS
DON'T MISS ANY NEW ARTICLE !
Get your FREE! E-Book & Have Every New Article Delivered Straight To Your Email-Box