StyleRef - if= "error" display " "

I use StyleRefs a lot, and have a questions.

In a header I have a styleref but sometimes the style is not used in the document and the field returns the standard "Error! No text of specified style in document." message.

Is there a way of having the styleref that will work normally if the style is present in the document, but not show the error message if otherwise?

many thanks

in basic Excel parlance :)

=if(StyleRef="error"," ", StyleRef)

Answer
Answer

You could use a field coded as:

{IF{STYLEREF "StyleName"}<> "Error!*" {STYLEREF "StyleName"}}

This will work for all Word versions.

Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field construction are all required.

Cheers
Paul Edstein
(Fmr MS MVP - Word)

3 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 14, 2025 Views 938 Applies to: