Recording a Macro
- 06:52
Understand how to record a Macro
Downloads
No associated resources to download.
Glossary
Developer Ribbon Macro Naming Status Bar VBATranscript
So how do we record macro? Well, there's a couple of ways to do this. The first way is on the developer ribbon, there is a record macro button. Another way is down on the status bar, there's a record macro button. Clicking either of these will start the recording process or you can use the shortcut, which is Alt L R.
And to use that shortcut, remember you'll need to have the developer ribbon turned on. Okay, so that's how we initiate the recording of a macro. The first thing we have to do is name our macro. We have to give it a descriptive name so something that's gonna mean something when I come back and look at this recorded macro. So the default name macro one isn't gonna be very useful for us. I won't really remember what it was I recorded it for, what this job was to do. So try and give them meaningful names. And there's some characters you can't have in macro names. So for example, you can't have spaces you also can't have certain other special characters such as dollar signs, asterisks and those kind of things. And obviously if you do use one of those special characters Excel will warn you and say that you're not allowed to. You can have numbers in the macro name, but note that you can't have a macro name that starts with a number. So you can have a macro called macro 1. You can't have one called 1 macro. So we're gonna do something very simple which is record ourselves entering our name into the spreadsheet. So I'm gonna call mine EnterMyName, and you'll notice that we can't have spaces so I'm just using capitalization to make it easier to read the macro name. As well as that, some people prefer to use underscore characters to separate the words in their macro name. Either of those two conventions is perfectly fine. The, as with so many things in Excel, consistency is key.
So whichever one you choose, just stick to it. I'm gonna come back and talk about the ways to run macros in another recording. So we're gonna ignore the shortcut key option but what we do need to talk about is where are these macros going to be stored? And there are three choices in this dropdown list. We have something called the personal macro workbook. We have a new workbook and we have this workbook. We very rarely use new workbook so I'm not even gonna talk about that one. The two main choices really that we have are do we want to store this macro in this workbook that I'm in now, or do I want to store it in something called the personal macro workbook? But this workbook option is pretty obvious. We're storing the code, the actual information it needs to run this macro with the workbook and it makes sense that I would need the macro workbook. I'd need the workbook open to be able to run this macro. So the two are intrinsically linked. The macro and the workbook that it goes with are together. So this makes it useful because it means that when I open the workbook, that macro is available. I can run the macro and then I can close that workbook. I can also send it on to other people if they need to do a job. I can send the workbook with the macro code so that they can run the macro. So that's the this workbook option. The personal macro workbook is a hidden workbook that gets loaded every time you start Excel.
Now this is useful for macros that I want to be able to run on any workbook. So maybe it's just a list of handy shortcuts that I do on lots of different spreadsheets and I'd like those to be available all of the time. So every time I come into work, I start Excel, my hidden personal macro workbook gets loaded automatically. And then all of those macros that I've got in that personal macro workbook are available for me to use on any other workbook. It's important to note that even though I run those macros on other workbooks, those other workbooks don't contain any macro code. The only code is stored with the personal macro workbook. So those are our two options. Personal macro workbook. For those macros, I want to be able to use in situations on any spreadsheet that I open and this workbook for those situations where I'm recording a macro that's only relevant to this particular workbook. Now, for this training purposes, I'm just gonna choose this workbook.
We should also enter a description about what it is this macro's job is, probably my name, when I recorded it. And just some simple information that's gonna help both me and anyone else who comes along later work out what it is that this macro is doing. I'm gonna leave mine blank again just for training purposes.
So once we click okay, we are now recording. How can we tell? Well, if we look at the status bar, you'll see our little button has changed. It now looks like a stop button and I can click this when I'm finished to stop recording. Or I could go to the developer ribbon and you'll notice that the record button has now changed to a stop recording button. Or I could use the same shortcut that I used to start recording, which was Alt L R, to go and stop recording. So it's a toggle to record and stop recording.
So now I can go and perform all of the actions that I want to do. So the only actions that I'm gonna do I'm gonna go to the cell B 5, I'm gonna type in my name and then I'm gonna hit enter. And that's it. And then I'm gonna stop recording. So there we go. We've recorded our first macro. How do we run it? Well, if I just delete that cell, then the shortcut to open the run macros dialer box is Alt F8.
You'll see the list of macros that you've got available to you. So both the ones that are in your personal macro workbook and the ones that are available in this workbook, select the one you want and then hit run.
And we'll run our macro.
Or to run your macros, you can go to the developer ribbon and then click on macros.