Hi, everyone! An interesting comment was posted on Friday asking about using VBA to add options to a Word setting that don't appear in the UI... and I thought that was a great topic for a post.
The question at hand was, essentially, whether you can specify a format for insertions and deletions in a Word document comparison other than the options that exist in the dropdown lists in the Options dialog box. The simple answer is no, but it's not that simple.
The fact is, if there's logic to it -- you can do it with code. In this case, I say that the simple answer is no because you can't do it through the built-in feature. The question of whether of not something can be automated often becomes whether the cost justifies the benefit. At the simplest end of the cost-benefit analysis is basic VBA you might use to automate a cumbersome document production task. If writing the code takes as long as executing the task -- and you only have to execute the task once -- it's not worth reinventing the wheel (unless you just want the practice writing code, of course :) But, if writing the code will take less time, or if you will need to execute this task frequently, the benefit is very likely to outweigh the cost of doing that bit of VBA work. No matter how complex the task becomes, and no matter what development solution you're using (some things might require moving outside of VBA into something like Visual Studio Tools for Office), the cost-benefit question is almost always what determines whether or not the thing can be done.
When the tasks get more complex - like trying to make an Office program do something it doesn't do (such as adding to the formatting options for document comparisons), you might need to create your own solution rather than utilizing the built-in feature to do this -- a potentially far more complex task.
Sometimes, the things that seem to be so simple on their face are really some of the most complex because of the capabilities or limitations of the built-in feature. One of the most common cases is the one introduced with the original question here about adding options to built-in formatting options. The limitation is that the feature comes with a fixed set of constants. So I'm going to discuss a bit about what constants are, how to use them, and when you can get around them.
Constants are just what they sound like -- constant...a fixed set of options.
Note that, from this point forward in this post, I'm going to assume that you have at least a very basic exposure to VBA and its terminology. If you're brand new to VBA but would like to jump in -- check out a webcast of mine from earlier this year Tips and Tricks for Using Basic Word VBA Every Day. Note that it's a level 300 webcast, so it's designed for Word power users who are new to VBA, but not at all new to Word.
Constants in VBA are a set of options available to modify an object or property. The simplest type of constants are boolean -- true or false. For example, when you set a userform control (such as an option button) to be enabled or disabled, you use the control's Enabled property, like so:
frmMyForm.optAccept.Enabled = True
When you type that equal sign in the line of code you will get a little dropdown list that contains just the options True and False. These are the available constants for the Enabled property. (Note that not all features that are limited to constants provide a dropdown list and whether or not you see these lists can depend on your VB Editor setup.)
In the case of the document comparison formatting options, you get a larger set of constants because the constants represent all of Word's available options for how inserted or deleted text should be formatted (such as bold or double-underlined). Take a look at the constants available for formatting inserted text:

There are, however, some cases when you get more options in VBA than you do in the UI ... one nice, simple example is with Bold or Italic font formatting. This formatting always toggles when you use it in a Word document ... you see this if you add bold or italic to a paragraph style. If, for example, you have a style that contains bold text and you create a new style based on the first that has regular text ... take the bold out of the first style and it will get added to the second style. That's because the setting always toggles -- if you base one style on another and change the bold or italic setting, the style definition will be set to have the opposite bold or italic (true or false) from the base style. So when one changes, the other toggles in kind.
But, in VBA, you can set the Bold or Italic font properties to always be true, always be false, or to toggle - which is the default.
But there are many cases where you can't expand on the available constants without going outside of the built-in feature. One good example was a question posed to me a few weeks ago -- asking for a way to add custom text into the page numbering within a table of contents. The page number formats are limited to the page number formatting constants available to the field code.
But, if you generate your TOC from styles -- you can write a quick and simple VBA solution to get exactly what you want in much less time than you might expect. Your TOC will be able to be updated as easily as a Word TOC created with the built-in Word TOC feature ... but, it will not actually be a Word TOC. It will look, smell, and taste like one -- but it will be a workaround. Of course, in this case, it might just be a workaround that's as simple as, and every bit as good as, the real thing -- depending upon what you need. Stay tuned later in the week for the code to do that ... I've got to get back to work now :)
Happy Monday everybody!