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 / August 2007

Tip: Looking for answers? Try searching our database.

Use current heading level in a field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
automandc - 01 Aug 2007 03:12 GMT
Is there a way to get the current heading level from a field?

I can't use a StyleRef field because I don't know what style to look for
(i.e. Heading 1, Heading 2 etc.)

Thanks

(I realize this is the VBA forum)
Russ - 01 Aug 2007 09:20 GMT
Read carefully about outline level in this link:
<http://word.mvps.org/FAQs/Numbering/ListString.htm>

> Is there a way to get the current heading level from a field?
>
[quoted text clipped - 4 lines]
>
> (I realize this is the VBA forum)

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

automandc - 01 Aug 2007 09:44 GMT
That's helpful, but it doesn't answer the question.  I want to place a field
in bodytext and be able to calculate something based on the Outline Level of
the immediately preceding heading.  I.e., if the text appears under Heading
1, then x=1; if it appears under a Heading 3, then x=3.

So. (1) can you get outline level from a field (I want to avoid VBA code in
this document); and (2) how do you find it for the immediately preceding
heading when the field is in the body?

Thanks.

> Read carefully about outline level in this link:
> <http://word.mvps.org/FAQs/Numbering/ListString.htm>
[quoted text clipped - 7 lines]
> >
> > (I realize this is the VBA forum)
Graham Mayor - 01 Aug 2007 10:17 GMT
There is no way you can determine from a field what the current paragraph
style is - you can do it easily enough in vba eg

Dim CurrStyle As Style
Dim x As Integer
Set CurrStyle = Selection.Style
If InStrRev(CurrStyle, "Heading") Then
   x = Right(CurrStyle, 1)
End If

but without vba ......

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> That's helpful, but it doesn't answer the question.  I want to place
> a field in bodytext and be able to calculate something based on the
[quoted text clipped - 24 lines]
>>
>>  drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ - 01 Aug 2007 10:49 GMT
Msgbox selection.paragraphs(1).previous.style
If the previous paragraph is style Heading 4, then that is what you will see
in the message box.

And like the link I gave you said:
Msgbox selection.paragraphs(1).previous.OutlineLevel
Will show the number 4 for Heading 4.

What's in the field? ALT/F9 will toggle reveal field code or field results.
I not sure what you mean about no VBA code in the document. Usually you put
code in a template and open a new document with that template, you don't
want to mess with another user's Normal.dot setup.
> That's helpful, but it doesn't answer the question.  I want to place a field
> in bodytext and be able to calculate something based on the Outline Level of
[quoted text clipped - 18 lines]
>>>
>>> (I realize this is the VBA forum)

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 01 Aug 2007 11:02 GMT
Oh, maybe you are asking for field code that will determine the previous
level of the previous paragraph? There is no special field code for that, as
far as I know. You would still have to use VBA to determine the Outline
level and store that in a variable which could be used in a formula field or
If..Then field.

> Msgbox selection.paragraphs(1).previous.style
> If the previous paragraph is style Heading 4, then that is what you will see
[quoted text clipped - 30 lines]
>>>>
>>>> (I realize this is the VBA forum)

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 01 Aug 2007 11:15 GMT
"Is there a way to get the current heading level from a field?"

I originally thought you meant that some field was applying a Heading style
and you wanted to know how to find out what Heading style level it was
applying.
Now I see that you meant to create a field to determine the heading style.

> Oh, maybe you are asking for field code that will determine the previous
> level of the previous paragraph? There is no special field code for that, as
[quoted text clipped - 36 lines]
>>>>>
>>>>> (I realize this is the VBA forum)

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Jonathan West - 01 Aug 2007 11:50 GMT
> That's helpful, but it doesn't answer the question.  I want to place a
> field
[quoted text clipped - 7 lines]
> in
> this document);

No.

> and (2) how do you find it for the immediately preceding
> heading when the field is in the body?

You can't.

Sorry the answer isn't more positive, but if it really can't be done, all I
can say is "it can't be done"

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

automandc - 01 Aug 2007 20:02 GMT
Thanks everyone.

By way of explanation, I have a very large document of numbered paragraphs.  
I am using Seq fields to apply the numbers.

At the end of every section, I want to leave "reserved" numbers in case I
insert or delete paragraphs, I don't have to renumber the whole document.

I can create a line that says "X to Y is Reserved" where X is the {SEQ \n}
(next number) and the Y is {SEQ \r Z}.  I can make Z static (i.e., always
adds 10), and I can even use formulas to make Z always end on a round number
(i.e., I currently have it add between 10 and 19 to get to the next ##9).

I want to be able to vary Z based on the level in the heading outline --
e.g., top level headings will reserve up to the next multiple of 100, 4th
level headings only reserve up to the next multiple of 10.  But the only way
to do that is to know what level in the heading outline the current text is
at.

Because many non-sophisticated people will be working in the document, I am
reluctant to use anything that requires code.

I think my workaround will be to add a "tag" to the document based on the
style of the next pargraph using some temporary VBA, and then later I can run
a find/replace to paste in the correct fields based on the type of "tag".  I
can either use some reusable code I have to find and replace with a field, or
just put the fields in the clipboard and replace with ^c.

So, thanks for the help.  It seems strange that you can't access this info,
since certain fields vary their behavior based on it (e.g., the \h switch in
the SEQ field).

> > That's helpful, but it doesn't answer the question.  I want to place a
> > field
[quoted text clipped - 17 lines]
> Sorry the answer isn't more positive, but if it really can't be done, all I
> can say is "it can't be done"
Peter Jamieson - 02 Aug 2007 17:06 GMT
FWIW, I had a pretty good look around at possible ways to do this with
fields - as you say, the \s switch in SEQ fields obviously knows when to
reset the sequence numbering, but I couldn't think of a way to use that.
Things might be easier if you were able to ensure that there was an
appropriate { SET level n } in every Heading n paragraph which you could
then use in subsequent SEQ fields.

Unfortunately, this is one of those areas where the software designers seem
(presumably accidentally, but when it's as thorough as this it sometimes
seems deliberate) to have closed off every possible way you might conceive
of doing it with fields. For example, an obvious possibility would be to
test the value of { LISTNUM LegalDefault \s 1 } (which should look like
1.1., 1.1.1. etc.) using e.g.

{ IF "{ LISTNUM LegalDefault \s 1 }" = "1.1." "were'at level X" "{ IF
.... }" }

but unfortunately, even if the LISTNUM fields always returned the right
values (and that may depend on very consistent use of heading styles,
outline levels etc.) you do not appear to be able to test the result of a
LISTNUM field (or AUTONUMLGL) or assign it successfully via SET for later
testing.

Peter Jamieson

> Thanks everyone.
>
[quoted text clipped - 62 lines]
>> I
>> can say is "it can't be done"
 
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.