The Anchorage
Personal website of Gregory K. Maxey, Commander USN (Retired)
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.
If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!
The purpose of this Microsoft Word Tips & Microsoft Word Help page is to illustrate an apparent anomaly in Microsoft Word when employing IncludeText fields together with Conditional If and TOC fields in a document and to offer a "passable" solution.
Layout and formatting of documents is not really my forte, but recently a client shared a pair of documents and explained a problem that he was having developing his desired document content using Conditional If, IncludeText and TOC fields.
Both his primary document file and the document file used as the IncludeText source had formatted content consisting of outlined numbered Heading 1 and Normal style text. Since pictures speak a thousand words:
The Primary document showing the fixed outline numbered Heading 1 text and Normal text with TOC, Conditional If and IncludeText Fields. |
The IncludeText source file showing outline numbered Heading 1 and Normal styles text and bookmarks. |
This shows his desired output:
What he actually got was a colossal disaster:
It seems that for some unfathomable reason, the presence of a top level Conditional If field in a paragraph formatted with an outline numbered heading style, breaks the link between the text and the numbering with consequential anomalies in both the paragraph text and the TOC .
My first approach was to grab a big hammer and use a "brute force" VBA procedure "Macro" that:
It was simple and worked to achieve the desired result. However, when I shared it with Word MVP Paul Edstein, he correctly pointed out that while working in this case; "clobbering" the If fields that way risks also clobbering any fields e.g., {Date} contained in the included text.
While there are no fields in the example included text, it is always important to be aware of the consequences of any VBA procedure. They indiscriminately do exactly as you instruct them to do which may not (as Paul pointed out) be desirable in every case.
Paul suggested it would be better to rearrange the fields and make the Include Text fields the top level fields containing nested Conditional If fields. In this arrangement, the Conditional If field are used to define the IncludeText bookmark. The new field arrangement is shown below:
The change in field arrangement also necessitates a minor change in the IncludeText source files. We need to add the "Null" bookmark.
After updating (a two stage process), this method results in a nearly perfect solution:
We are still left with the undesirable empty paragraph between paragraphs 4 and 5 in the resulting document.
The reason should be clear, we put a paragraph there and used it to define our field arrangement. Even when we put nothing in it, it is still there as an empty paragraph. We can't expect it to go away as if by magic.
Note: In an IndudeText field with IF field arrangement
where one of two or more blocks of text from the Include Text file will be
inserted, the method describe above would be acceptable.
Once again, I was prepared to dust off my hammer and resolve this
situation with VBA. However, after a brief consultation with Paul, I learned
that the final steps for a perfect
solution are a different placement of the IncludeText fields in the primary
document and a minor tweak to the bookmarks in the include text file.
It has been quite some time since I have published a tips page here that didn't include VBA. This one started life with that intention. I am really pleased that Paul showed interest in this issue and so generously shared is experience developing an alternative and better solution. Thanks Paul!!
Both the primary document file and file used for the included text can be download here: File Pack.
That's it! I hope you have found this tips page useful and informative.
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.
If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!