StyleRef field plus some text

Hi all
This should be an easy one :)

I have a StyleRef field (and thanks to macropod, et al) only displays when the style in question is used in the file.

What I would like to do is add some text to the StyleRef field, so when the field displays it shows the StyleRef-text and the plain text as well.

{STYLEREF  "StyleName" "text"}

but I don't know the switches/syntax for this to work

cheers :)

I am not sure what the StyleRef field construction that you are using returns if the style is NOT used in the file, but assuming that it is a space, you could use a construction such as

{ IF { STYLEREF "StyleName" } <> " " "{ STYLEREF "StyleName" } text" " " }

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

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.

here is what I have (from macropod)

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

this works fine, displaying and not displaying the styleref text as required

but if I add (like you say - if I got it right)

{ IF{STYLEREF "stylename"}<> "Error!*" {STYLEREF "stylename" } text" " " }

the styleref is displayed but not the extra text

I tried your code, the standard error is displayed if the style not used, and the Text is displayed regardless; I am after the text not to displayed when style not used and no error shown; and the text to display along with the StyleRef-text.

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.

You can use a field as TrueText without quotes, but once you add anything to it, you need the quotes, so what you need here is (you can omit the FalseText since it's blank):

{ IF { STYLEREF "stylename" } <> "Error!*" "{ STYLEREF "stylename" } text" }

Microsoft MVP (Word) since 1999
Fairhope, Alabama USA
http://ssbarnhill.com
http://wordfaqs.ssbarnhill.com
Screen shots captured with TechSmith's Snagit

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.

Thanks Suzanne for the reply

sorry but this does not work for me, the "text" appears regardless of the style use.

If there is no text with the Style that the StyleRef is looking for, there is nothing displayed.

If the style is used, the text with the style AND the "text" to appear.

Say Jabberwocky is the text with the style applied, then the StyleRef field should display "Jabberwocky text".

If style not used, nothing displayed.

Many thanks :)

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.

All I can say is that it works as expected for me (I used Heading 1 as the referenced style). The position of the quotes is crucial. You must have quotes around the entire TrueText and around the stylename if it is more than one word but not anywhere else, lest Word interpret it as FalseText.
Microsoft MVP (Word) since 1999
Fairhope, Alabama USA
http://ssbarnhill.com
http://wordfaqs.ssbarnhill.com
Screen shots captured with TechSmith's Snagit

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.

ah your right, I missed the quote after the Error!*"[space]

many thanks :)

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.

The field Suzanne gave you is correct (and a fine piece of field coding).

Typing field codes can be tricky. I copied Suzanne's field into my document. Then I selected the two StyleRef fields and used Ctrl+F9 to make them real fields. Then I did the same thing for the entire IF field. I deleted the typed braces and pressed F9. The field disappeared because I did not have any text in the stylename style. I selected the word I wanted and created a new Character style named stylename. The word Jabberwocky appeared in the header along with the text.

Note, the preceding thread on this can be found here. http://answers.microsoft.com/en-us/office/forum/office_2010-word/styleref-if-error-display/546f004e-a16d-4099-8a76-0f75eb57279e

Volunteering to "pay forward" the help I've received in the Microsoft user community.

Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com

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.

Yep, many thanks Charles, got it working fine :)

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 October 5, 2021 Views 436 Applies to: