Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Setting up running headers in a document by using STYLEREF FIELDS

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andreas - 28 Dec 2006 09:37 GMT
Hello,

I recently wrote a macro code that is setting up running headers (odd
and even) in long documents with several sections (all headers and
footers are not linked to previous).

The odd page headers show the text from the numbered heading 1 levels
and I achieved this by telling Word:

Set rng = sect.Headers(wdHeaderFooterPrimary).Range
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
       "STYLEREF  ""Heading 1"" \n "
       rng.Collapse wdCollapseEnd
rng.Text = " "
       rng.Collapse wdCollapseEnd
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
       " STYLEREF  ""Heading 1"" "

Now the even page headers show the text from the numbered heading 2
levels:

Set rng = sect.Headers(wdHeaderFooterEvenPages).Range
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
       "STYLEREF  ""Heading 2"" \n "
       rng.Collapse wdCollapseEnd
rng.Text = " "
       rng.Collapse wdCollapseEnd
rng.Fields.Add rng, Type:=wdFieldEmpty, Text:= _
       " STYLEREF  ""Heading 2"" "

The trouble is that there are a couple of sections that haven't!! got a
heading level 2 (just a heading level 1). In these sections, the above
macro code causes Word to insert the text from heading level 2 on even
page headers from the previous section.

Hence my question: How can I tell Word that whenever a section hasn't
got a heading level 2, all headers (odd and even) should show only the
text from the heading level 1

Help is appreciated.

thank you in advance.
Peter Jamieson - 28 Dec 2006 11:15 GMT
If your document are "fire and forget", i.e. the user can do anything with
them after they are created and you can't get them to run macros, then I do
not think you can do anything about this.

If you can postprocess the document that the user creates, you should be
able to detect the presence or absence of a heading style in each section
and modify your header/footer accordingly using VBA.

If you can get the users to collaborate, or if, for example, you are able to
provide a macro that inserts paragraphs with styles Heading 1 and Heading 2,
then you could do something along the following lines:
a. whenever you insert a Heading 2 style paragraph, insert a { SECTION }
field either at the beginning or the end of the text, formatted so that its
result is invisible. The easiest approach is to add a { SECTION } field at
the end, formatted as white text so that it cannot be seen.
b. use the following nested field in your header:

{ IF "{ STYLEREF "Heading 2" }" = "*{ SECTION }" "{ STYLEREF "Heading 2" }"
"whatever text you want if there is no heading 2 style in the section" }

This has a chance of working only if
a. the { SECTION } field is in all the necessary Heading 2 style paragraphs
b. the heading text is not too long for the comparison to fail (I think it
may do so if the text is longer than around 127 or 255 characters, and
perhaps in other circumstances)

There may be other ways to do this so that the user can't accidentally
undermine the approach, but that's the one I can think of right now.

Peter Jamieson

> Hello,
>
[quoted text clipped - 38 lines]
>
> thank you in advance.
andreas - 28 Dec 2006 21:52 GMT
Peter,

very good advice. Thank you very much.

Regards,

Andreas

Peter Jamieson schrieb:

> If your document are "fire and forget", i.e. the user can do anything with
> them after they are created and you can't get them to run macros, then I do
[quoted text clipped - 69 lines]
> >
> > thank you in advance.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.