Running Macros - Worksheet Object
- 02:17
Understand how to add a Macro button to a workbook
Downloads
No associated resources to download.
Glossary
Form Controls VBATranscript
So to add a button on the worksheet to run a macro, what we need to do is we go to the Developer ribbon. Then we're gonna go to the Insert dropdown here. And you'll see there are two sections of controls. The top section are called Form Controls and the bottom ones are ActiveX controls.
We need to focus on the Form Controls that we're gonna add in. And the one that I'm after is the very first one, which is just called Button.
Once you've clicked it, you'll see your cursor changes from the thick Excel cursor into a very fine, thin cursor. And I'm gonna move over the spreadsheet, and I'm just gonna draw a button shape, a rectangle, just drag it out onto the spreadsheet.
And as soon as I've done this, it will pop up the Assign Macro window, allowing me to go and choose the macro that I'd like this button to run. So, I simply choose it and click on OK.
And now we have our button on the worksheet. Obviously at this point, I can just click into the button, delete the text, change the text to whatever I like just so I can resize the button while I've got these handles available. And then when I'm finished, just click away onto the spreadsheet. You'll notice here I don't have quite enough room for the text. So, in fact, what I'm gonna do is I'm just gonna right click onto this and just make the button a little bit wider so that when I click away, there we go, we can see the full text.
Once I've done that, you'll see again my cursor changes as I mouse over this button now. And every time I click this button, this is gonna run my macro. So if we think about this, if I'm gonna add a button on the worksheet, it makes sense that the macros that I'm gonna run are stored with that particular worksheet and workbook. So, macros that you've recorded into this workbook, they're gonna be the kind of macros that you want to run with buttons on the worksheet.