Reputation: 85
I'm having to convert some documents which had been built in OpenOffice over to word, and one thing which seems overly complicated in Word is conditional text. OO had some features which made this a breeze, but I'm thinking I'm missing something in Word.
For more simple pieces of text I've used the {IF {DOCVARIABLE xxxx} = ...}
method which seems to work well with single lines of text.
For longer blocks of text I've tried using a similar method but inserting an Autotext block. This works well if the content is static, but if the content I'm inserting needs to be edited, updating the document ends up replacing any changes with the Autotext block. So this method won't work for parts of my document.
Most of the search results I'm seeing use some variation of the two methods above. Is there something else I can use which allows blocks of text, possibly including tables, to be conditionally inserted or hidden and also editable?
Macros are okay since this is how I'm setting various DOCVARIABLE
parameters in the document.
I'm using Word 2016 on Windows 7.
Upvotes: 1
Views: 1603
Reputation: 85
After doing more experimenting, it looks like I can use bookmarks to do what I need. I can select the block of text I want to conditionally show/hide, then create a bookmark for the selection. Then in my macro I can hide the section when necessary with:
ActiveDocument.Bookmarks("MyBookmarkName").Range.Font.Hidden = True
or show it again using False
instead of True
. This seems to hide tables and other things within that block of text. I'd love it if the Word developers would add some of the features for this type of thing which are in OpenOffice.
Upvotes: 1