So you’ve got some code and you want to be able to run it, but opening up the list of macros (ALT+F8) and choosing the one you want just isn’t quick enough. Or if you have a lot of macros it can get tiresome looking through your list to find the right macro before running it.
So what do you do? You assign the macro to a shape, or you can use a shortcut sequence of keys.
Inserting a Shape
Excel has lots of shapes you can use with a multitude of configuration options to play with. You can read our post on Excel Shapes to learn how to insert and configure them. But it's as simple as going to the Ribbon : Insert -> Shapes and choosing the shape. Then use your mouse to position the shape and drag it to the size you want.
You can then play around with the look of it but don’t go nuts. K.I.S.S. I’m just going to use a rectangle, change the colour to green and add some text. Use the text on your shape to convey something meaningful like what the macro will do – which in my case is “Fix Everything”. It‘s a little macro I wrote one day.
Assigning a Macro to the Shape
Right click on the shape and then click on Assign Macro
The list of macros pops up, click on the macro you want, then click OK. You’ll still be editing the shape at this point and you must click off it before you can run the macro, so just click in any cell.
Now just click on your button and run your macro. I just did and I Fixed Everything, so I can go home early 🙂
Using a Shortcut Key Sequence
If you have fingers that are extremely dextrous from maybe playing too much Tetris (yes I have been playing games for a long time) or FPS games (Half-Life/Battlefield/COD anyone?) then maybe a keyboard is your weapon of choice.
In this case you can use a sequence of keys to run your macro. In Excel press ALT+F8 to bring up your list of macros.
Click on the macro you want to use – only click once! Then click on Options and you’ll see the box below.
By default Ctrl is included in the shortcut sequence. You don’t want to hijack a pre-configured shortcut like Ctrl+S, Ctrl+X etc, so I try to use Shift as well to make my sequence unique. In this case I’m going to use CTRL+SHIFT+X
Click OK and you are back to the list of macros. Here’s where the interface isn’t very good. There’s only a Cancel button, but you have to press it, or click the red X button to close the window. Either way I don’t like this as there should be an affirmative option to make me feel like I’m actually saving the changes I just made.
But, click Cancel anyway and your shortcut key sequence is saved.
Shape vs Shortcut
The shape obviously only appears on the sheet you’ve created it on. The shortcut is available from any sheet in your workbook. You can decide which is best for you.