I have to generate documents for work in Word format.
We have template we have to follow, but these are mind-numbingly difficult to use and I am convinced there is a better way to do it, and I was wondering if someone out there could point me in the right direction for further reading.
As I said, we have templates in Word which we need to go through and amend. For example, it will say:
“By the [insert] day of the [first/second/third] [week/month] of the contact, the parties shall…”
I have repeated the line about in exactly the way it is written, the square brackets and options appear in the template.
Amending the document it quite literally done by jumping the cursor down the line using option and arrow, and deleting the relevant parts. It feel prehistoric and is massively time consuming. I’m certain there is a better way to do it.
What I want to do
What I would like to do is create some new templates with place holders in place of the square bracketed words so I can simply tab through the place on the page to the variable and either chose from a drop down menu or, simply insert custom text. This would be a million times quicker and would be worth the investment of time of creating new templates.
The other thing I would like to do is have self-correcting variables in the document. For example, if I need to refer to either “company” or “companies” within the document, I can change this once, and it will correct every instance within the document. I appreciate this could be done with find and replace, but I wondered if this could be linked to the same process.
Any ideas gratefully received.
It sounds like Mail Merge might help you? I haven’t done this in years, but googling gave me this site that seems to have decent guidance: How to Use Mail Merge in Microsoft Word 2016 for Mac
You can do this using Word “fields”, and in particular document properties.
To define properties go to Menu File, Properties, Custom - define your property in this dialog. For example I defined a property called shoesize with a value of 23.
To insert the field in the template, on the Ribbon, Insert, Field (above Date & Time on the right of the Ribbon), Choose Document Information on the left, DocProperty on the right and then either enter the field name in quotes after DocProperty or click options… and select it.
Then to update the values for a given document just go to the File Properties Custom again and change the values of the properties.
Update fields by selecting the whole document (Command a) and update fields. To find the shortcut for updating fields, right click in a field and look for it. It’s just F9 on Windows, I don’t know why it has to be a fistful of keys on Mac.
I wrote a python script that takes Microsoft word templates and populates the fields that you supply to it. it used to take my assistant hours to put all the templates together that we had to use, and now the whole set can be generated in 10 seconds flat. I’m not so sure my script is robust enough to address the kind of variable language that you would like to include, but it may not be that hard to customize the script to your needs. (If you’re into the scripting thing.)
Would you mind sharing this script?
A while back I’ve tried to do something following the steps of Automating the Boring Stuff with Python but the formatting of the resulting documents was an issue.
Gladly. I can’t right now, but I will post soon.
Another idea - set up the document as a form and lock it so that only the spaces for the values can be filled in. Pulldown should be an option. It’s a while since I did this but I can look into it and see if it works for your use case.
I have now published the Python script on GitHub: GitHub - THV/trialpracticetools: A series of helper scripts and apps for managing civil litigation matters.
There are two things that you need to know. First, the script makes use of a library called docx-mailmerge, available here: docx-mailmerge · PyPI. Second, the way that I structured this, the Word documents that you use need to have field codes that match the codes in your script. I’ve added a sample template so you can see what I did.