IF field causing problem with TOC

B

book_worm71

For now I've given up on the TOC issue I was having in one of my chapters,
but this problem is occurring in the main document and is becoming a
deal-breaker. Any help is appreciated.

I'm using includetext to add chapters to my document. Some of these chapters
are included conditionally.

Every chapter that is included conditionally (using the "IF" field) causes a
phantom heading to show up in the TOC of my main document. It looks like this:

23 Include........28
24 MACROS........29
25 Segmentation........31
1........34
26 Instruction Formats........34
1........38
27 Addressing Mode........38

And it is as simple as that. If I remove the "IF" field that surrounds the
included chapters, the TOC appears normal.

If I apply heading styles in the main documents over the original headings
in the included documents (and preserve them using \* MERGEFORMAT) this also
solves the problem, but this is not a viable solution for many reasons.

Can anyone help or tell me what I'm doing wrong? Thanks in advance.
 
M

macropod

Hi book_worm71,

I suspect the problem is due to you having the IF field attached to a paragraph formatted in the Heading Style. You need to attach
the field to the start of the following paragraph and embed the Heading Style's paragraph mark in the IF field.
 
L

Lene Fredborg

Note that macropod’s post appeared just when I was going to post the text
below. In my test, the if field is formatted as Body Text and I still see the
problem (however, I may not understand macropod’s description correctly). If
macropod’s suggestion solves the problem for you, you will not need my
solution - by here it is anyway.

I read your previous posts and tried to reconstruct the scenario you describe.

I can reproduce the error with the superfluous TOC entries. In my test, the
problem only occurs with numbered items, i.e. if I change the heading style
in use to unnumbered, the superfluous TOC items disappear.

The only solution I could find was a macro that deletes the superfluous
paragraphs and locks the TOC so that it is not updated unintentionally. I
created the following macro - see the comments in the macro. Note that I only
tried to identify the paragraphs to be deleted by checking its length - you
may need to change that or to adjust the length. I used 5 chars as the limit
- it may not be sufficient - and if you have very short headings that _are_
correct, another kind of check may be required instead.

Sub UpdateRepairLockTOC()

Dim oPara As Paragraph
Dim oTOC As TableOfContents

Set oTOC = ActiveDocument.TablesOfContents(1)

With oTOC
'Unlock TOC
.Range.Fields.Locked = False

'Update TOC
.Update

'Delete the superfluous items
For Each oPara In .Range.Paragraphs
'Check length of paragraph - skip last empty TOC para (len 1)
If Len(oPara.Range.Text) > 1 And Len(oPara.Range.Text) <= 5 Then
oPara.Range.Delete
End If
Next oPara

'Lock the TOC - can be unlocked manually with Ctrl+Shift+F11
.Range.Fields.Locked = True
End With

Set oTOC = Nothing
End Sub

--
Regards
Lene Fredborg - Microsoft MVP (Word)
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
B

book_worm71

Hi macropod,

Thanks for the suggestion. I didn't apply any styles to my fields in the
main document. No matter where I put my cursor in the "IF" and "INCLUDETEXT"
fields, or the lines above and below, the style is indicated as Normal. I
used the Style Inspector to look for text level formatting as well, just in
case. Am I misunderstanding what you mean by having it attached to a style?
The chapter documents have formatting, of course, but I'm not sure how to
test your solution as it relates to those. Also, I'm not sure how I would go
about embedding a paragraph marker in a field.
Lene, thanks for the suggestion. We do need to have our chapters numbered
so it looks like this may be a problem. I think a macro may be beyond the
scope of workarounds that we're willing to implement, in lieu of choosing
another solution.

macropod said:
Hi book_worm71,

I suspect the problem is due to you having the IF field attached to a paragraph formatted in the Heading Style. You need to attach
the field to the start of the following paragraph and embed the Heading Style's paragraph mark in the IF field.

--
Cheers
macropod
[MVP - Microsoft Word]


book_worm71 said:
For now I've given up on the TOC issue I was having in one of my chapters,
but this problem is occurring in the main document and is becoming a
deal-breaker. Any help is appreciated.

I'm using includetext to add chapters to my document. Some of these chapters
are included conditionally.

Every chapter that is included conditionally (using the "IF" field) causes a
phantom heading to show up in the TOC of my main document. It looks like this:

23 Include........28
24 MACROS........29
25 Segmentation........31
1........34
26 Instruction Formats........34
1........38
27 Addressing Mode........38

And it is as simple as that. If I remove the "IF" field that surrounds the
included chapters, the TOC appears normal.

If I apply heading styles in the main documents over the original headings
in the included documents (and preserve them using \* MERGEFORMAT) this also
solves the problem, but this is not a viable solution for many reasons.

Can anyone help or tell me what I'm doing wrong? Thanks in advance.
 
M

macropod

Hi book_worm71,

You'd code the IF test along the lines of:
IF{Toggle}= TRUE "Heading to Include.¶
Text to Include.¶
"}
and make sure the field is attached to a non-Heading Style paragraph - for example:
{IF{Toggle}= TRUE "Heading to Include.¶
Text to Include.¶
"}The quick brown fox....

--
Cheers
macropod
[MVP - Microsoft Word]


book_worm71 said:
Hi macropod,

Thanks for the suggestion. I didn't apply any styles to my fields in the
main document. No matter where I put my cursor in the "IF" and "INCLUDETEXT"
fields, or the lines above and below, the style is indicated as Normal. I
used the Style Inspector to look for text level formatting as well, just in
case. Am I misunderstanding what you mean by having it attached to a style?
The chapter documents have formatting, of course, but I'm not sure how to
test your solution as it relates to those. Also, I'm not sure how I would go
about embedding a paragraph marker in a field.
Lene, thanks for the suggestion. We do need to have our chapters numbered
so it looks like this may be a problem. I think a macro may be beyond the
scope of workarounds that we're willing to implement, in lieu of choosing
another solution.

macropod said:
Hi book_worm71,

I suspect the problem is due to you having the IF field attached to a paragraph formatted in the Heading Style. You need to
attach
the field to the start of the following paragraph and embed the Heading Style's paragraph mark in the IF field.

--
Cheers
macropod
[MVP - Microsoft Word]


book_worm71 said:
For now I've given up on the TOC issue I was having in one of my chapters,
but this problem is occurring in the main document and is becoming a
deal-breaker. Any help is appreciated.

I'm using includetext to add chapters to my document. Some of these chapters
are included conditionally.

Every chapter that is included conditionally (using the "IF" field) causes a
phantom heading to show up in the TOC of my main document. It looks like this:

23 Include........28
24 MACROS........29
25 Segmentation........31
1........34
26 Instruction Formats........34
1........38
27 Addressing Mode........38

And it is as simple as that. If I remove the "IF" field that surrounds the
included chapters, the TOC appears normal.

If I apply heading styles in the main documents over the original headings
in the included documents (and preserve them using \* MERGEFORMAT) this also
solves the problem, but this is not a viable solution for many reasons.

Can anyone help or tell me what I'm doing wrong? Thanks in advance.
 
B

book_worm71

Hi macropod,

We're trying to single-source our documents, so I've been including the
chapters as separate documents, like so:

{if processor ="68hc12" {includetext "68hc12_addressing_mode.doc"}}

It's not feasible for us to place the heading/text itself directly inside
the includetext field because then that content would not be reusable in
other documents. Is it still possible to apply your technique in these
circumstances? I feel like maybe I'm still misunderstanding you - sorry!

Thanks for the help.
 
M

macropod

Hi book_worm71,

You could use something along the lines of:
{if{processor}= "68hc12" "Heading to Include.¶
{includetext "68hc12_addressing_mode.doc"}"}The quick brown fox....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top