Microsoft Word & Simple Macros
Do you use macros in Microsoft Word?
I know many don't. Macros can get a bad rep because of security implications or their perceived complication, but when you're carrying out repetitive tasks on your own computer, they're neither.
They're actually handy to know about, as well as being simple, quick, and easy to create and use.
What Are Macros?
Macros are just a set of pre-recorded steps that you perform in your application. For me, it's mostly in Word. Perhaps you're more familiar with them in Excel? I have created a fair few macros in Excel, but 95% of my time is using Word.
What Do We Mean by Pre-recorded Steps?
When we record a macro, Word tracks what you do in the application.
It doesn't track the mouse or record mouse-clicks, but it does track and record keyboard actions and the items that you click on.
So, if I click on File and then Print, it won't record me clicking on File, but it will record me clicking the print action at the end.
Make sense?
When Should I Use a Macro?
In its simplest form, we use macros for automating repetitive tasks (like entering all your customer's information in each time).Or creating, writing, and formatting a new book for publishing:
(The above is the software I created to help create, format, and publish print and ebooks)
In the video, below, I 'm co-authoring a new book with my wife (the book, How To Write Thai, is almost ready for editing; the book has an accompanying video course. The video shows the worksheets for the book/course).
As you'll see in the video, I've used a lot of tables throughout and, after inserting all the content, I then modified the heading styles. This created extra space allowing for 2 more rows in each table.
There are several ways to add 2 more rows to the bottom of each table (some much quicker than others), but for something simple like this, I'd record and run a macro. It takes seconds to setup and do.
Before we get to the video, let's just talk a little about the code that it uses.
VBA
A macro is written with Visual Basic for Applications (VBA).
VBA allows you to do some powerful things, but when we record a macro, it does produce ugly and bloated [VBA] code.
Though most professional programmers (of which I am not) wouldn't dream of running a macro, rather coding it faster by hand, for our purposes, it gets the job done quickly and easily.
Word takes care of it all for us. No-one else needs to see the code and it's job done.
Of course, if you wanted to take macros/VBA a step further, then you can do some wonderful and powerful things - they're there to optimize and make our lives easier - but this is a whole new all-game and beyond the scope of what I'm doing here.
How Do We Use Macros?
However, recording a macro isn't the be-all-and-end-all, we still need to use it in our document.
In the video, I also show you how to:
- assign the macro to a custom keyboard shortcut key and
- add it to the Quick Access Toolbar and then run it from there.
I hope you like the video.
Macro Code
(So you can check you've done it right.)
Here's the macro code that's both created by Word and tidied up by me:
Initial code:
This is the code that Word records:
Sub Macro4()
'
' Macro4 Macro
''
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
Selection.MoveRight Unit:=wdCell
End Sub
Tidied up code:
This makes it tidier and a little faster:
Sub insert_2rows()
Dim x As Integer
Selection.MoveRight Unit:=wdCell
For x = 1 To 6
Selection.MoveRight Unit:=wdCell
Next x
End Sub
The Video:
Macros are very easy to setup and use. So, if you find yourself having to do repetitive tasks in Word, then see if you can record a macro to help you. It might save you some time and some sore fingers.
Let me know in the comments below if you found this post useful?