With this post, we will record our first macro!

Excel VBA — Record­ing first macro | Intro­duc­tion to macros and VBA 03

First of all, we want to open a file with macros. What we have here is a piece of infor­ma­tion that says ‘Mar­cos have been dis­abled’. You need to click the Enable Con­tent but­ton (Fig. 1)

Information concerning macros
Fig. 1 Infor­ma­tion con­cern­ing macros

If you don’t want to click the Enable Con­tent but­ton con­stant­ly, like me, go to the Devel­op­er tab, then click on the Macro Secu­ri­ty com­mand, then the Enable VBA macros radio but­ton (Fig. 2)

Enable VBA macros command
Fig. 2 Enable VBA macros command

We can also go to the Trust­ed Loca­tion part and press OK. It will also work for all files and help us with too many noti­fi­ca­tions or mes­sages (Fig. 3)

Trusted Location
Fig. 3 Trust­ed Location

Today, we want to record very sim­ple macro. We just want to write the TODAY func­tion in cell A2. This cell should be select­ed before we click the Record Macro com­mand. Since the cell is select­ed let’s write the equal sign, then TODAY, then click the Ctrl+Enter key com­bi­na­tion. It’s impor­tant to use this short­cut. That’s all we need in our first macro (Fig. 4)

 Ready function
Fig. 4 Ready function

Now, let’s delete this val­ue and then press the Record Macro. In the win­dow that has appeared, the first thing we do is choos­ing the macro name. We can use the name of our func­tion’s name. In most cas­es we should’t do that, how­ev­er our case is real­ly sim­ple. It’s only macro, not a VBA func­tion. Then, we choose whether we want a short­cut for our macro or not. If the box is emp­ty, it means that our macro has­n’t got a short­cut. If we write there a let­ter or a sign, this will mean that we have a short­cut. The Ctrl key is a default key for each short­cut. It also applies to the Shift key. That’s why, let’s hold the Shift key and press D at the same time. I’m using D, as ‘today’ is ‘dziś’ in Pol­ish. If we don’t want any short­cuts, we just press the Back­space but­ton. Next, we have the loca­tion of our macro. We have a choice of Per­son­al Macro Work­book, New Work­book or This Work­book. Let’s choose the Per­son­al Macro Work­book, as it’s the most sig­nif­i­cant one. We can also add a descrip­tion in the next part, how­ev­er, in most cas­es the name should be enough to tell us what this macro does. We have already cho­sen the name, short­cut and stor­age place, so we can press OK. You need to be care­ful when press­ing OK, because that’s the point when the record­ing process starts. It means that each action you do in this work­sheet will be record­ed (Fig. 5)

Record Macro window
Fig. 5 Record Macro window

Now, our Record Macro com­mand changed into the Stop Recording com­mand. The but­ton in the bot­tom left cor­ner of the sta­tus bar also changed. It means that we don’t need to go to the Devel­op­er tab to stop the record­ing (Fig. 6)

Stop Recording button
Fig. 6 Stop Record­ing button

Let’s write =TODAY and press Ctrl + Enter again. Then press the Stop Record­ing but­ton. It’s cru­cial to press this but­ton so that Excel does­n’t record any unnec­es­sary code. 

Now, since we added a short­cut to our macro, let’s use it in cell C2 by press­ing the Ctrl+Shift+D short­cut. Some­thing actu­al­ly appeared in the cell, but we need to change the for­mat­ting to get the date (Fig. 7)

Formatting modification
Fig. 7 For­mat­ting modification

Now, we can see that we have our date, wher­ev­er we use the short­cut (Fig. 8)

Dates
Fig. 8 Dates

https://www.youtube.com/watch?v=NBEE3mA45xg