StyleRef is lost in user defined heading

R

RWN

Wrd2k

I thought I'd try and get a handle on using styles in a template that
I'm setting up (vs. doing it through VBA). Wanted to do this after a lot
of reading about styles and becoming convinced that it was "the only way
to go" in Word.

I have three headings (using the built in "Heading 1, 2 & 3") that are
to appear on the left side of the page.
The user wants the heading repeated on the right side in a smaller
Font/emphasis etc.
I couldn't see how I could do it except by defining another heading on
the next line.
I set up three user defined styles ("shd1" ..2 & ..3). Then, modified
the "Heading x" styles "Format for the following paragraph" to point at
my user defined styles.
This worked very well (format the text as "Heading x" - <enter> and it
sets up the appropriate subheading format).

Then I wanted to have Word automatically fill in the subheading(s), and
that's where I got into trouble!
I inserted fields using a "StyleRef" in the user defined subheadings,
pointing each to the "Heading x" value that precedes
it. This worked like a charm UNTIL I deleted the headings/closed the
template and opened it as a "New" document to test it.
While the formatting and subheading process works I no longer have the
"StyleRef" values.
(I should note that I used the "StyleRef" in the Header-pointing at the
Heading 1 value-and it works fine.)

Am I missing something here or am I correct in assuming that a
"StyleRef" cannot "live" in a user defined heading?

Any "hints"??
 
S

Stefan Blom

The purpose of the STYLEREF field is to show the "current" text
or numbering of the specified style. The field will show an error
message if it doesn't find any occurrence of that style.
 
R

RWN

Stefan;

Thanks for your response (both here and elsewhere:)).
I fear, however, that I did not explain my problem well enough.

I'm not getting any errors.

I defined a "Heading 1" style. For the "Format for the following
paragraph" I defined my own style "shd1"
If I enter text and format it to "Heading 1" THEN insert the "StyleRef"
(nominating the "Heading 1" text) in the "shd1" it works ok.

I then kill both the "Heading 1" and the "shd1", leaving a blank
template (save for the header), as the user would see it upon opening as
a document.
When I open it and enter text as "Heading 1" <enter> it correctly
displays the next line as my "shd1" but the "StyleRef" is gone (no
errors, just not there).

I'm assuming that it does not retain the "StyleRef" in a user defined
style because I had no problem with defining it as such in the "Header".
The "Header" displays the error ("Error! No text of specified style in
document") when I open the document but as soon as I enter the "Heading
1" text it picks it up just fine (it picks it up even before I hit
enter).

I've done a lot of "Googling" on the subject but can't seem to get any
hits on the subject which makes me think I'm missing the point
somewhere(?).

Again, thanks for your time.
 
C

Charles Kenyon

StyleRef is a field, not part of any style.

If I'm following you, it is not there if you put it in a text box or frame
that you inserted while your insertion point was in the header that you
deleted. That deletion would have deleted the textbox as well.

Try inserting in your dummy heading a macrobutton field as a prompt for your
heading text. Then move your cursor to the beginning of your heading and
insert your text box with the StyleRef field. Next, select your entire
paragraph and save it in your template as an AutoText entry.

Delete it. Your text box is gone, right?

Type the name for your AutoText entry and press the F3 key. The macrobutton
field and your AutoText entry are back! You can use this method anywhere in
documents created with your template to enter such a heading with a
side-note styleref.

Hope this helps.
--

Charles Kenyon

See 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.
 
R

RWN

Charles;
I think I'm starting to get it

Because the "StyleRef" that works is in the Header, it stays (because
the header "holds" fields/text et al).
A StyleRef inserted on a line (or paragraph) is not retained in the
Style because a style is just that, a style, not a container for text.
Correct?
If so, great, I learned something (and they say "you can't teach an old
dog new tricks" - well, my kids say that anyway).

Because it worked in the Header and I'd set up a "Header" Style, I came
to the wrong conclusion.

Makes sense to me - now to try your idea.

Thanks for the time.
 
S

Stefan Blom

RWN said:
A StyleRef inserted on a line (or paragraph) is not retained in the
Style because a style is just that, a style, not a container for text.
Correct?

Well, numbered paragraphs can include text as part of their
numbering formatting; and if you set the number format to "None",
you can have a paragraph style that includes static text.
However, you are right in assuming that a style cannot store
"live" text, such as a field.
 
Top