Macros for Word tables

The Office suite has a fully-fledged programming language built into it. Visual Basic for Applications [VBA] is a sub set of the very powerful Visual Basic used to develop full applications on the Windows platform. In Office, VBA can extend almost any feature or function within Word and, to a lesser degree, in PowerPoint and Excel. We use VBA to add specific features to our templates to help users complete certain tasks that maybe are too complex for the general user, or a need to combine standard features, but in a specific way that relate more closely to the template itself.

In a recent project we developed a set of very complex templates that had to be used to format multiple column, design-like layouts in Word. Word can do all of the things I am about to mention, but the average user rarely has the training or knowledge to complete the same level of design. Word is a word processor, not a page layout software, so some restrictions or limitations apply.

A macro can be used to format tables for a more creative solution that a user may find too time-consuming to do themselves.

Let’s look at an example to help appreciate what can be done. Tables are a very useful and necessary feature in Word. They come in all shapes and sizes and can be used for page structure, as well as for conventional tables of data. In a number of projects we have to format tables to follow a specific format, colour scheme and design. A lot of people do this manually each time, but that’s a big time-waster if you have dozens to do in one document.  The ‘out of the box’ method, and the one you would find in the Microsoft manual, would be to set up a table grid style, but there are some interesting issues that make this a bit of a non-starter. The table format setup works very well for the basic details, but a number of settings and attributes can’t be set, and would be problematic for most of the corporate guidelines we work to. For this reason, we would recommend that a macro is developed that allows us to manage all aspects of a new table.

The macro would manage the basic insertion of the table, even asking the user how many rows and columns they want. It would add the table into the page specified by the cursor position, and format all of the rows, columns, colours, spacing, style use and cell indentation to match any guideline. We can also fix a number of formatting issues that cause problems with a normal table on behalf of the user.

Tables can be managed in two ways: adding in new tables, like the example above, or by formatting an existing table that the user already has. Let’s assume, for a minute, that the user has been supplied with a document or two that hold all of the content for a new report they have to compose in their corporate style. The simplest method is to copy the tables from the supplied document to the new corporate one and then format it to the right style. A couple of tables is not a great deal of work, but a dozen or more would take a fair amount of time. By developing a macro that formats a table in a particular way, the user benefits from an almost instant formatting of the table in front of them.

Imagine ‎how much time is saved when giving them a custom function of this kind.

Leave a Reply

Get in touch