Document pack / form filling / client onboarding documentation

H all

Im trying to create a macro to fill out word documents,
in my work day, I often need to onboarding clients and I have to re-key data for multiple documents, things like client name, address etc, and its such a time waster,

id like to be able to run through a pack of docs and fill them out with data, which I only have to enter once,

I would really love it if someone could help me create a robust macro that can do this task.

so far ive come up with the following, which works,
it opens up the word file, and then replaces the placeholders in the word doc,

but I have a feeling there has to be a more sophisticated way of doing this, would love your help.

Best regards

Can you post an image of the blank form in Word (not showing any confidential info, of course!).


thanks rob

its just a simple doc really with the placeholder,
my plan is to import PDFs into word, then layer these placeholders over the top.

Im not sute this is the slickest way, I would really appreciate some guidance,
Would also love to be able to auto fill out PDFS, infact to be honest that would probably be better for me.

FWIW I would personally tend to do this with one Keyboard Maestro variable name rather than many – structuring the value of that name as a JSON string representing a dictionary of keys and values.

Hard to say without having any impression of where the data is coming from, but it's possible that it may already be JSON-structured, or readily translated into a JSON format.

Keyboard Maestro provides a very convenient and flexible %JSONValue% token.

token:JSONValue [Keyboard Maestro Wiki]

That's a tough task to fully automate. One thing that would help greatly is if you can set the document up as a Word form.

That page explains how it works. You lay out your document as you like, and wherever you have variables to insert, insert a text box. Then protect the document, close it, and open it. Now pressing Tab only takes you from field to field. Here's a stupid dummy form I made using some placeholder text:

Word test form

When you open a form document, the first field is selected, and only fields can be selected, so Tab or Right Arrow moves between them.

With the form in place, I would then get rid of your Keyboard Maestro multi-variable input form (you're the only user of the macro, right?), which requires a lot of tedious copy-and-paste work, back and forth, and waiting on Word's Replace All to show up.

Instead, if you're using Keyboard Maestro version 11, I'd gather my input using the Prompt for Snippet action:

This creates an input box where you tab to each field and enter the values:

You might wonder about the underscores. I used those because Prompt for Snippet returns not just your input, but also the labels for those inputs. You could have no labels, but that would be confusing. By using two underscores (or any other characters that aren't likely to show up in your actual text), I can strip the labels out with a regex search.

Say I filled out my form as shown above; the local_theInput variable would now hold all six lines of my input:


The remainder of the macro then becomes incredibly simple: All it does is activate Word, then loop through the lines in the local_theInput variable, pasting each into a field then pressing the right arrow:

You'll notice a disabled Pause action there; it wasn't needed on my Mac, but if yours won't keep up with the field hopping and pasting, enable it and change it as necessary.

I have attached the above sample macro, as well as the Word form document I used to test it with. You'll want to read up on forms, as they're just a bit tricky (you create them with the document unprotected, then protect it, save it, close it, and reopen it to test), but not overly complicated. You have to have the Developer toolbar item showing, but the Microsoft link above explains how to do that.

_Word Form Test.kmmacros (4.7 KB)

Word form (11.8 KB)

If you don't have Keyboard Maestro 11, you can do something similar though it's trickier to get the multi-line input into one variable. If you'd like that solution, let me know and I'll see if I can put it together.

Hope this helps!


EDIT: Accidentally uploaded just one action from the macro the first time; corrected now.

1 Like

thank you both for taking the time to help me out both responses taught me things I didn’t realise I could do and will be a big help in future so thank you, really appreciate you putting that together,

I really don’t know much about coding so JSON looks a little bit complex for me, but it insipred me to mess around with chatGPT and ended up with a python script thats fantastic to be honest I cant quite believe how good it works.

I had no idea you could do Microsoft forms, the phython script only really works well if I use forms, for some reason phython doesn’t like replacing text in tables or text boxes, but handles forms really well,

python script allows me to scan an excel file for placeholders in column A of my spreadsheet, and then copy and paste data from col B, into my Microsoft Word templates and it’s rapid, its exactly what I needed,

I plan to use keyboard maestro to trigger the python script, thats my next venture.

Any tips for doing this?

Thanks both


Glad you found a solution that works! You can easily trigger a python script with the Execute a Shell Script action, and set it to point to the file on the drive (or just paste the text in the script box itself).


thank you Rob :smiley: