Conditional Text in Word Documents

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Does Word handle conditional text? I've checked the on-
line help, but it's not mentioned.

I have a document from which I'd like to create two
versions, say domestic and international. To do this, I
need the ability to selectively hide and display text,
either words, sentences and paragraphs, based on some
condition or trigger (e.g., FLAG) that I manually set.
As an example, one version might display (and print)
metric units while the other might display British units.
Both sets of information would be in the same base file.

Does Word offer this capability??

Thanks..........Rob
 
Yes, Word does this, through IF fields.

Insert => Field...

The exact method depends on which version of Word you are using. You could
set your trigger using an ASK field which sets the value of a bookmark.

For more complex fields, you insert the field braces by pressing F9 and type
the field. When you press Alt-F9, field codes are displayed/hidden. A sample
IF field:

{ IF { Ref "IntToggle" } = "domestic" "1 inch" "2.54 cm." }

The ASK field would look like:

{ ASK IntToggle "Is this for domestic or international use?" \d domestic }

You would need a macro to trigger the updating of your ASK field.

The following would do it:

Sub UpdateAskFields()
Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldAsk Then
oField.Update
End If
Next oField
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldIf Then
oField.Update
End If
Next oField
End Sub

The next two macros would update your fields automatically when the document
is created from your template or when the document is opened.

Sub AutoOpen()
UpdateAskFields
End Sub

Sub AutoNew()
UpdateAskFields
End Sub

Using Tools => Customize... you can attach your update macro to a key
combination or a menu command.

Hope this helps,

--

Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://addbalance.com/usersguide/index.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
Rob,

First as a disclaimer let me say there is always the possiblity of a better
way, but this could be done with a DocProperty Field and IF fields. For
example if you created a Document Property titled say "Version" you could
use the result of that property to toggle the display of an IF field.

Here is what an IF Field might look like:

{ IF {DocProperty "Version" } = "Metric" "Meters" "Yards" }

This field compares the value of the DocProperty "Version" with the word
"Metric" if is matches, it returns "Meters" if not, it returns "Yards." All
you would have to do is change the DocProperty Version from Metric to
Bristish Units (or anything else for that matter).

HTH
 
Back
Top