Microsoft says that ” A macro is a series of commands and instructions that you group together as a single command to accomplish a task automatically. “
It basically means that a Macro is a set of instructions that can be repeated.
In other words, it is a set of commands that can be repeated.
To understand this little better, Let’s consider this scenario where you have to insert a footer with copyright text in a lot of documents.
To handle this challenge, we can simply record whatever we are doing and replay in every document.
Here is a video which covers the same content
Creating a Macro by simply recording
First, we are going to click on the Developer tab and click on a Record Macro. If you do not have Developer tab visible, check out this post to enable developer tab.
Let’s focus on only one single option, which is the Macro Name. Let me call it InsertCustomFooter.
After providing the macro name, click OK. Then go to insert tab, click on Footer and choose Blank.
After that let’s type our custom message:
Press ALT CTRL C to insert the copyright symbol in MS Word)Hint
Then go to Insert and click Insert Date and Time to insert today’s date. Click OK.
Now, type in some standard text like
All Rights Reserved. Align it Center.
It should look something like this:
Copyright © May 31, 2019 All Rights Reserved
That’s all we want to do for this demonstration
Let’s go back to the Developer and click on Stop Recording.
It’s time to run this macro!
Let’s open a new document which does not have a footer.
Click on developer tab and then click Macros to see the list of macros. Select the macro name and click Rub. It will give you exactly the same footer that was recorded earlier.
You may have noticed a problem here. The problem is missing a period in the copyright text. To resolve it, click the Macros button on the Developer tab, select the macro name and click Edit.
From the code, find the below line:
Selection.TypeText Text:=" All rights reserved"
And change it to include a period.
Selection.TypeText Text:=". All rights reserved"
Congratulations! Now you know what is a Macro. You now know how to create, and even edit the code a bit.
Be sure to check the next article about Editing the Macros for mode details.