Skip to main content

Better Tools 2: Automated Punctuation in Microsoft Word

This post describes two tools that automate the formatting and punctuation of tables and bulleted lists in Microsoft Word. It complements and earlier post – Better Tools: Efficient Table Management which described Word tools for quickly recording content into tables and numbering the entries.

A key goal is to demonstrate how Office’s development language can be used to automate manual tasks, and to encourage readers to add the ability to create simple, timesaving macros to their skillset.

A link to a free download of the tools is given at the end of the post.

Setting the scene

As a Business Analyst, I am often required to prepare text-heavy documents such requirement statements, risk assessments, business cases and many others. The content needs to be concise, easily digested by the reader, and quick and easy to prepare.

To meet these objectives, I make extensive use of tables and bulleted lists. Both allow me to quickly capture content, and when I’m on a roll, I often find that I haven’t formatted or punctuated the content correctly. If I slow down and get picky with the presentation, I can lose focus on the ideas and information that I’m trying to capture.

I have developed some tools to help me correct the presentation once I’m ready. I have used VBA, the development tool that comes with Microsoft Office. I’ll describe the tools and mention some of the development concepts that they cover.

Formatting Table Content

This tool puts a “.” character at the end of every paragraph in a selected range of table cells. It does this only when there is no other punctuation character already present.

This means you can dump a bunch of ideas and down in a table and avoid the tedious task of checking each entry and adding the punctuation later. You can select the entire table and process it all with a single key press, and be sure that it won’t change anything you have already entered.

At the same time, it removes blank lines at the end of the selected cells. These blank lines are easy to add accidentally, and can be are hard to spot. If they are not removed they can make row spacing look strange.

In this before and after image, you’ll see that the “.” characters have been added and the blank line at the bottom of the cell removed. The existing punctuation “:” has been retained. 

coomber Img1 Oct28From a coding perspective, this routine is simple demonstration of the way that VBA allows the code to step through a range of cells within a table. It then steps through the paragraphs within a given cell, and then through the characters in a given paragraph. You can use the same concepts to step through a document and check for certain content and make necessary changes. 

The code also shows how to access information about the current position in the table and do things like skipping the content in header rows and in the first column where punctuation is unlikely to be required. Finally, the code shows how to update cell content using text manipulation.

Automatic Punctuation of Bulleted Lists

Apart from making frequent use of tables, another way of efficiently capturing information in text documents is to use bulleted lists. I like to use bulleted lists because the introduction or preceding statement sets the context for the list entries, and means that the reader can focus on the key messages without distraction.

One of the issues I find with bulleted lists is the varying punctuation standards that my clients expect. Some want grammatically correct clauses with semi-colons and use of “and” to make the list a correctly formatted, if somewhat long, sentence. Other clients like “.” characters at the end of each list entry, just want a “.” character at the end of the final entry.

This variation in style causes me two main problems. Firstly, I tend to dump ideas as quickly as I can and have to punctuate correctly later. Secondly, I often like to reorder the entries, so need to change the punctuation, especially if I add an entry at the bottom.

I decided to create a tool that would punctuate the list according to a chosen style, and correct existing punctuation if I chose a different style or change the order of the entries.

The punctuation styles used are:coomberImg2 Oct28

Here is an example of how the tool adds punctuation using a “semi-colon” style. You don’t have to select the list, just place the cursor anywhere in the text and the entire list is selected automatically. coomberImg3 Oct28
coomberImg4 Oct28 Here is an example of how the tool corrects the punctuation when the entry order is changed. Note that the “and” has been moved to its correct location and the final “.” added.

I have built the tool to handle bulleted lists inside tables, so you can apply bulleted list formatting and the fill in any other punctuation using the tool described at the start of this post.

The tool will also handle bulleted lists in documents that use numbered paragraphs, which share many of the internal characteristics of lists.

From a coding perspective, this tool uses some special logic to determine the extent of the bulleted list. Some of the more elegant methods available didn’t handle the complexity of table cell boundaries and the presence of numbered paragraphs, so I settled on a fairly boring but reliable step through each list entry, looking up to determine the start of the list, and looking down to find the end of the list. This approach allows the code to test for table cell boundaries and changes in formatting style.

Once the paragraph numbers that define the boundaries of the list have been determined, the code simply steps through each of them, making changes and adding the punctuation required for the selected style using simple text handling methods. 

To keep things simple, the code strips out all existing punctuation first. This seems a little inefficient but has the virtue of being simple, and the execution is quick enough.

A downside of making these text changes, perhaps unnecessarily, is the potential to create large numbers of change indications if Track Changes is on. I have therefore added logic to temporarily turn off track changes processing when applying the style, and switching it on again afterward.

Conclusion

I use these tools frequently every day, they save me time, and encourage me to make the best use of efficient text entry, and allow me to present this in a consistent and reliable manner with a few keystrokes.

I hope the coding techniques used will provide some useful guidance too.

Downloading the Tools

The table tools can be downloaded (for free) here. You can also find more information on VBA in general, and more specific information on setting the tools up for use. I use them every day, but you should test them thoroughly to ensure that they work for you. Please feel free to adapt the tools to suit your own needs.

Don’t forget to leave your comments below.