Word and Visual Basic for Applications (VBA): Worth the Effort? (Part 1)

Aug 28, 2015

Visual Basic for Applications (VBA) is a programming language developed by Microsoft that is included with Word and other Microsoft Office products. It allows you to write small programs (called scripts or macros) to manipulate the functions of Word that are normally accessible through the standard user interface: menus, dialogs, buttons, drop-downs, checkboxes, radio buttons, and so on.

Why is programmatic manipulation of Word functions useful? You can write macros to do repetitive tasks automatically so that you don’t have to manually repeat the task over and over. The process of performing repetitive tasks automatically is sometimes referred to as ‘automation’. Repetitive tasks can include applying styles, reformatting tables, or importing content from other sources. The macros do the work for you, and they do it faster and more accurately.

As illustrated below, in repetitive task scenarios, a little investment in programming effort can lead to big time savings, especially as the size of the task increases.

Time spent on repetitive tasks

What Can You Do with Macros?

The following are some examples of interesting use cases:

  • Applying formats automatically (for example, setting table headings to repeat when a table expands to a new page)
  • Validating formats (for example, checking that a file conforms to your template and reporting any anomalies)
  • Importing/exporting content to and from other applications (for example, taking content from a spreadsheet, importing it into Word, then formatting it automatically)
  • Working with DITA files (Word VBA has a library of functions specifically for this purpose)

These are just some examples. Since you have access to all document components, there is potential to be very creative.

What’s in It for the Writer?

Learning to use VBA has many benefits for a technical writer. With VBA, you can improve efficiency and accuracy by getting the computer to perform many of your mundane tasks. Computers are excellent at repetitive work (such as applying styles) while humans struggle somewhat. We’re not good at robotic work and we typically need something more engaging and challenging. Creating macros fits into this category. Once you get started, it can become infectious and you subconsciously look for new ways to apply your newfound skills.

Also, adding knowledge of a programming language enhances your skills portfolio. You’ll have a higher level of confidence when conversing with a developer audience and you are more likely to engage with them on a more productive level. Even better, by learning the basics of VBA for Word, you automatically acquire knowledge that allows you to write similar code for other Microsoft Office products, such as Excel.

What’s So Special about VBA Anyway?

VBA is compelling for many reasons. First, Word is ubiquitous. No matter where you work, there is a good chance you will have access to Word. By association, any investment in learning VBA can have broad application.

The VBA language is pretty intuitive and the learning curve is less steep than other programming languages. You don’t need to know a lot of technical details and the language is human-readable. In many cases, you can quickly interpret what the code is doing.

The VBA Editor is a fully-featured environment that includes helpful features like IntelliSense, which offers assistance with VBA syntax as you type or on demand. In addition, the VBA Editor has great debugging features, quick access to help, and an object browser.

The VBA Editor

Finally, it is possible in Word to record your actions, then view the VBA code that was generated for those actions. This feature helps new users become familiar with VBA. If you don’t know how to code an action, just record it and view the generated code afterwards. You can learn a huge amount with just this approach.

Is It Difficult to Learn?

If it’s your first experience of a programming language, it may seem difficult at the beginning. However, in many ways VBA is a great starting point:

  • It is perhaps the easiest of all programming languages used in the technical writing domain.
  • It is object-oriented, which may sound daunting, but actually helps understanding. In the case of Word VBA, the objects you work with are familiar: Documents, Paragraphs, Words, Tables, Rows, Columns, Cells, and so on.
  • The VBA Editor provides an environment that makes writing macros much easier.
  • There is an abundance of sample code, demos, and tutorials. Chances are, the task you want to achieve (or something similar) has been done before, and you can leverage existing code. There is also a huge user community with an array of forums, message boards, and experts to help solve problems.

What Are the Stumbling Blocks?

Most inexperienced writers have blinkers on when it comes to all things programming. Terms such as objects, inheritance, and polymorphism just frighten writers to death. Don’t be put off by the jargon. To get started, all you need to do is focus on a few fundamentals. It is not as difficult as you may think!

Programming terminology

Writers think of programming as a very specialized subject. In general, this is true, but there are cases where non-programmers with some basic knowledge can become quite productive and VBA for Word certainly fits that category.

The final stumbling block is that writers often don’t know where to start. In this series, we’ll do just that: show you the basics and point you in the right direction.

Is It Worth the Time Investment?

Every writer’s situation is different, so only you can decide. You may work in a publications group that uses Adobe FrameMaker or other tools, so you may not want to invest time in learning about VBA for Word.

You may never have a requirement to do any scripting or you may simply have no interest in it, and that’s OK too. However, as you broaden your experience in the world of software documentation, gaining some knowledge of programming would be to your advantage. Where better to start than VBA for Word?

In this series, we introduce a few fundamentals to help you get started with VBA and possibly whet your appetite for further knowledge and exploration. If you are new to VBA, have you encountered scenarios where you think VBA could be useful? If you’ve already used VBA, do you have any helpful hints or suggestions for prospective new VBA users? Feel free to share your thoughts.

Share This

Share This

Share this post with your friends!