Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-21-2018, 09:25 AM
Levi92 Levi92 is offline Styleref field returns error Windows 10 Styleref field returns error Office 2016
Novice
Styleref field returns error
 
Join Date: Oct 2018
Posts: 4
Levi92 is on a distinguished road
Default Styleref field returns error

Hello everybody!

I am about to lose my mind trying to create this [insert bad language] header field.



So in my current document I want the current chapter name displayed in the header. Nothing easier than that using the Styleref Header 1 field. But this field returns an error
on pages with no header 1. Now I want to create an If field that does not return an error, but this is where I struggle.

My code: IF STYLEREF 1 = "Error!*", "", STYLEREF 1

While I am very good at VBA and creating functions in Excel, I have no clue how the syntax here works...

Last edited by Charles Kenyon; 10-21-2018 at 01:32 PM. Reason: Mark as solved
Reply With Quote
  #2  
Old 10-21-2018, 12:11 PM
Charles Kenyon Charles Kenyon is offline Styleref field returns error Windows 10 Styleref field returns error Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

The IF field in Word is case-sensitive. You need the field braces inserted by Word (not typed).

See Paul Edstein (macropod)'s answer here for the exact construction you need: https://answers.microsoft.com/en-us/...6-0f75eb57279e


This is also shown in the portion of my page on fields at: StyleRef fields.
Reply With Quote
  #3  
Old 10-21-2018, 12:22 PM
Charles Kenyon Charles Kenyon is offline Styleref field returns error Windows 10 Styleref field returns error Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by Levi92 View Post
Hello everybody!

***
But this field returns an error on pages with no header 1.

***

It should only return an error when there is no text using Heading 1 anywhere in the document, not just on that page.

Note, there is a big difference between header and heading styles.
What is the difference between headings and headers?
Reply With Quote
  #4  
Old 10-21-2018, 12:29 PM
Levi92 Levi92 is offline Styleref field returns error Windows 10 Styleref field returns error Office 2016
Novice
Styleref field returns error
 
Join Date: Oct 2018
Posts: 4
Levi92 is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
The IF field in Word is case-sensitive. You need the field braces inserted by Word (not typed).

See Paul Edstein (macropod)'s answer here for the exact construction you need: https://answers.microsoft.com/en-us/...6-0f75eb57279e
Thanks for the quick reply, Charles!

I have seen that post, but it does not work for me.

I have attached a picture of my code. As you can see this outputs "Heading 1" even though there is currently no header in that document,
Attached Images
File Type: jpg test.png.jpg (30.3 KB, 16 views)
Reply With Quote
  #5  
Old 10-21-2018, 12:38 PM
Charles Kenyon Charles Kenyon is offline Styleref field returns error Windows 10 Styleref field returns error Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

As Paul said, you cannot set this up using any of Word's dialogs. It has to be typed into the document and you need to use Ctrl+F9 to insert the field braces.

Your field does not look like his. It does not have the same structure.

His: {IF{STYLEREF "StyleName"}<> "Error!*" {STYLEREF "StyleName"}}
Yours originally: {IF STYLEREF 1 = "Error!*", "", STYLEREF 1}
Yours from the dialog: {IF STYLEREF "Heading 1" <> "Error!*" "" STYLEREF "Heading 1"}

If you edit the field you have from the dialog and select: STYLEREF "Heading 1"
then press Ctrl+F9 to make that a StyleRef field, it should work. Right now, it is being read as text rather than as the field.


If you used Alt+F9 to toggle field code display, after you are done editing the field, remember to toggle display of field results back on. If you used Shift+F1 to toggle an individual field, press F9 to update the field.


Note the missing braces, and the added commas. Your original field does not follow the required field syntax although it would be good as an Excel function or in vba. Your second does not have the nested StyleRef fields. Remember, too, that the spaces are important.
Reply With Quote
  #6  
Old 10-21-2018, 12:44 PM
Levi92 Levi92 is offline Styleref field returns error Windows 10 Styleref field returns error Office 2016
Novice
Styleref field returns error
 
Join Date: Oct 2018
Posts: 4
Levi92 is on a distinguished road
Default

Quote:
Originally Posted by Charles Kenyon View Post
As Paul said, you cannot set this up using any of Word's dialogs. It has to be typed into the document and you need to use Ctrl+F9 to insert the field braces.


Your field does not look like his. It does not have the same structure.


His: {IF{STYLEREF "StyleName"}<> "Error!*" {STYLEREF "StyleName"}}
Yours: {IF STYLEREF 1 = "Error!*", "", STYLEREF 1}


Note the missing braces, and the added commas. Your field does not follow the required field syntax although it would be good as an Excel function or in vba. Remember, too, that the spaces are important.
Thanks for clearing this up. I read Paul's post at least twice but apparently I was blind or stupid or both. It works now!
Reply With Quote
  #7  
Old 10-21-2018, 01:30 PM
Charles Kenyon Charles Kenyon is offline Styleref field returns error Windows 10 Styleref field returns error Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
I read Paul's post at least twice but apparently I was blind or stupid or both. It works now!

This stuff is complex and finicky. It makes most of vba look easy! Paul is the master of fields. He has a number of tutorials pinned to the beginning of this forum. They are worth downloading and perusing.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Styleref field returns error Remove Carriage Returns in Address Block Merge field alan100 Mail Merge 5 12-12-2017 08:32 PM
StyleRef field shows <> Stoic Word 2 04-20-2017 04:42 AM
query returns garbage after 255 chars from a text field word_user Word VBA 0 06-02-2014 02:34 PM
Problem using a StyleRef field in footer sleake Word 10 06-27-2013 07:45 AM
Styleref field returns error StyleRef field Ulodesk Word 4 03-21-2012 11:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:35 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft