At Codit, we like to standardize our documents. We have lots of templates to fill in and one of the parts that we ‘need’ to fill in, is author information (see below).
This post attempts to help out some of my colleagues in semi-automating this, using a macro.
I always tended to do this manually, until at a certain point I got fed-up and decided to use a simple VBA macro to do so. I always figured it was not a big deal, but didn’t know how and this particular blog post is mainly to get my co-workers an easy way of being able to copy the template as well as providing some readers with a quick way of copying the basic script.
Disclaimer: I am in no way an experienced VBA macro writer, I just wanted to provide a quick and easy way to use as a starting point.
So, I created the following macro, to be able to fill in my contact details:
Sub CoditContactMe() Selection.MoveRight Unit:=wdCell Selection.TypeText Text:=Application.UserName Selection.MoveRight Unit:=wdCell Selection.MoveRight Unit:=wdCell Selection.TypeText Text:="Architect" Selection.MoveRight Unit:=wdCell Selection.MoveRight Unit:=wdCell Selection.TypeText Text:="<email>" Selection.MoveRight Unit:=wdCell Selection.MoveRight Unit:=wdCell Selection.TypeText Text:="<phone_number>" Selection.MoveRight Unit:=wdCell Selection.MoveRight Unit:=wdCell Selection.TypeText Text:="n/a" End Sub
It’s dead simple really, it’s all about positioning my cursor on the “Name:” column in the table and with the click of a button.
First, you need to enable the Developer Toolbar
Right-click the Word ribbon and click “Customize Ribbon”:
Next, enable the Developer Toolbar, like so and click OK:
Now, you have the Developer toolbar and you can click the Macro button:
Then, just copy/paste the macro above in the code editor:
Click Save and close the editor.
Now, you still need a quick access button. To do that, again, right click on the Ribbon and choose Customize Quick Access:
Select the Macros, select your macro an and add it to the toolbar.
You can click “Modify” to select the icon you want and click OK.
From then on, you have a quick access macro button which you can use to fill in your contact details or to fill in anything else you need filled in, in the template:
If you come up with any additional macros, please leave a comment.