Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to suppress TOC and index rebuild before printing? 1

Status
Not open for further replies.

Dodiad

Technical User
Dec 3, 2008
6
US
I write technical documentation for a small-to-medium-sized software company. I’ve been trying to solve a couple of persistent formatting glitches in my TOCs and indexes, but Word seems determined to frustrate my efforts. I’m just about at my wit’s end, so I’m hoping somebody here can offer a useful suggestion.

The first problem is a familiar one: Jason tabs in my table of contents. I’ve followed all the advice in [link //word.mvps.org/faqs/formatting/TOCJasonTabs.htm]Dave Rado’s MVP article on the subject[/url], defined my heading styles with a macro using named list templates, disabled auto-update for all styles, etc., but Word still insists on tweaking my tab settings whenever I rebuild the TOC. So I’ve written the following macro to fix them:
Code:
Sub FixTOCTabs()
'
' FixTOCTabs macro
' Eliminate spurious tab settings from document table of contents
' 
    With ActiveDocument.TablesOfContents(1).Range.Paragraphs
      .TabStops.ClearAll
      .Reset
    End With '.ActiveDocument.TablesOfContents(1).Range.Paragraphs
    
End Sub 'FixTOCTabs
This seems to work fine when I run it, but still doesn’t solve my Jason tab problem, for reasons explained below.

The second problem affects the index. My document is a reference manual for an application programming interface. The index simply lists the API functions with the page numbers of the sections describing them. So each section heading includes a hidden index marker of the form [tt]{ XE "function_name" }[/tt]. In the index, I want the function names to appear in the distinctive (monospace) computer code font, with the associated page numbers in normal body font. Other word-processing programs (such as FrameMaker) provide ways to specify such formatting information in the index tag, but Word, as far as I know, does not. I’ve tried formatting the index tags themselves with the character style I want applied to them in the index ([tt]cfix[/tt], for “code font in index”), but that format doesn’t get picked up and applied to the resulting index entry. If anyone reading this knows of a way to specify this kind of formatting for index entries, I’d love to know about it; but lacking that, I thought I could manage it with a macro to apply the formatting after building the index:
Code:
Sub FixIndexFormat()
' 
' FixIndexFormat macro
' Apply correct character formatting to index entries
' 
    Dim theIndex As Index
    Dim indexRange As Range
    Dim indexEntries As Paragraphs
    
    Dim indexEntry As Paragraph
    Dim entryRange As Range
    Dim formatRange As Range
    
    
    Set theIndex = ActiveDocument.Indexes(1)
    Set indexRange = theIndex.Range
    Set indexEntries = indexRange.Paragraphs
    
    Set formatRange = theIndex.Range
    
    For Each indexEntry in indexEntries
      
      Set entryRange = indexEntry.Range
      With entryRange
        
        formatRange.Start = .Start
        
        With entryRange.Find
          
          .Execute FindText:=vbTab
          
          If .Found Then
            formatRange.End = .Parent.Start
            StatusBar = Reformatting index entry " & formatRange.Text
            formatRange.Style = "cfix"
          End If '.Found
          
        End With 'entryRange.Find
        
      End With 'entryRange
      
    Next indexEntry
    
End Sub 'FixIndexFormat
Now I can intercept the Update Fields command and automatically adjust the formatting for the TOC and index whenever they’re rebuilt:
Code:
Sub UpdateFields()
' 
' UpdateFields macro
' Intercept Update Fields command to fix TOC and index formatting
' 
    Selection.Fields.Update
    
    Dim selRange As Range
    Dim tocRange As Range
    Dim indexRange As Range
    
    
    Set selRange = Selection.Range
    
    Set tocRange = ActiveDocument.TablesOfContents(1).Range
    If tocRange.InRange(selRange) Or selRange.InRange(tocRange) Then _
      Call FixTOCTabs
    
    Set indexRange = ActiveDocument.Indexes(1).Range
    If indexRange.InRange(selRange) Or selRange.InRange(indexRange) Then _
      Call FixIndexFormat
    
End Sub 'UpdateFields
So far, all of this works just fine: whenever I update fields in my document, if the TOC and/or index are included in the selection their formatting gets repaired just the way I want it to. The problem arises when I go to generate a PDF of my document. As soon as I select the Print command, I see the message [tt]Word[/tt] [tt]is[/tt] [tt]repaginating[/tt] [tt]"API[/tt] [tt]Reference.doc"[/tt] appear in the status bar, followed by [tt]Word[/tt] [tt]is[/tt] [tt]updating[/tt] [tt]the[/tt] [tt]table[/tt] [tt]of[/tt] [tt]contents...[/tt], and then [tt]Word[/tt] [tt]is[/tt] [tt]searching[/tt] [tt]for[/tt] [tt]index[/tt] [tt]entries[/tt] and [tt]Word[/tt] [tt]is[/tt] [tt]building[/tt] [tt]the[/tt] [tt]index.[/tt] These rebuilding operations do not seem to be going through the Update Fields command, and hence are not getting intercepted by my UpdateFields macro. The result is that the damned Jason tabs and incorrect character formatting get put back into my TOC and index before the PDF is generated. I can’t see any way to create a PDF with the document formatted the way I want it. Has anyone got any constructive suggestions?

Thanks in advance for any help you can offer.


 
Hi Dodiad,

Your Index should use Styles "Index 1", "Index 2", etc. If you change these Styles, you shouldn't have to keep on reformatting your index.

If you go to Tools > Options > Print tab (Word 2007: Office Button > Word Options > Display tab) there is a checkbox under "Printing options" labeled "Update fields" (Word 2007: "Update fields before printing"). Uncheck this and the update before printing shouldn't happen.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Thanks, Tony, that Tools > Options > Print > Update fields option did the trick. (I’m Mac-based, so in my case it’s actually Word > Preferences > Print > Update fields, but never mind...).

One of the problems with Word is that all those numerous user preference options are not well documented; I wouldn’t have discovered that one without your help. How it got turned on in the first place is a mystery in itself, but it’s fixed now and my document is printing fine. Thanks for your help! (Thanks also to you or whoever it was that fixed my oversight on the subject line of this thread.)

I have another question regarding field updating, which I’ll post in a separate thread.

Thanks again for your help--


--Dodiad
 
Just wanted to add, in regard to this from Tony:
Your Index should use Styles "Index 1", "Index 2", etc. If you change these Styles, you shouldn't have to keep on reformatting your index.
I am using [tt]Index[/tt] [tt]1[/tt] style (the index is only one level deep). The problem is that I want two different fonts in each index entry: computer font for the function name and normal body font for the page number. Whichever of those I define for the [tt]Index[/tt] [tt]1[/tt] paragraph style, the other needs to be applied separately as a character style. The question was how to specify such a character style to be applied on top of the character format for the [tt]Index[/tt] [tt]1[/tt] paragraph style. Unless there’s some way I don’t know about to specify that in the index tag, I’m stuck with going back and applying the character style programmatically, entry by entry, after building the index.
 
Nope, unless Tony can prove me wrong, you are indeed stuck with programmatically changing the part of the paragraph - entry by entry - you want different. The Index 1 style applies to the whole paragraph, as do all paragraph styles.

The issue is that you want only part of the whole paragraph a different format.

Glad to see you using an explicit Character style. Bravo.

Gerry
 
Hi Dodiad,

Regarding your TOC, I wonder if you've made the correct changes. You say:
defined my heading styles with a macro using named list templates, disabled auto-update for all styles, etc., but Word still insists on tweaking my tab settings whenever I rebuild the TOC
but the MVP article to which you refer relates to changing the TOC styles, not the heading styles. You need to change the TOC styles to get the desired results.

Cheers

[MS MVP - Word]
 


Macropod wrote:
macropod said:
…the MVP article to which you refer relates to changing the TOC styles, not the heading styles. You need to change the TOC styles to get the desired results.
I said I’d followed all the advice in Dave Rado’s article. That includes this
Dave Rado said:
Make sure your heading styles are tab-free – in the case of list numbered heading styles this is only possible of you define the styles programmatically
as well as this:
Dave Rado said:
Make sure the left tab in each of your TOC styles aligns exactly with the hanging indent; and that the right tab aligns exactly with the right margin; if they don't, you'll get a Jason tab (but even if they do you might).
As to the first, I have defined all my heading styles programmatically, with a macro linking them to a named list template, with [tt].TabPosition[/tt] = [tt]wdUndefined[/tt], all strictly according to Dave’s advice as well as Shauna Kelly’s here. As to the second, my TOC styles are defined as follows:[ul][li]TOC 1: Left 0, Hanging 18, Right 0, Tabs 18L, 468R[/li][li]TOC 2: Left 18, Hanging 24, Right 0, Tabs 42L, 468R[/li][li]TOC 3: Left 42, Hanging 36, Right 0, Tabs 78L, 468R[/li][/ul]
As you can see, all of the L tabs align exactly with the paragraph hang. The document has 1-inch (72-point) margins on an 8.5-inch (612-point) page, so those 468R tabs align exactly with the right margin. Yet when I build my TOC (without the repair macro shown in my first post upthread), I end up with TOC 1 tabs at 18.45 or 24.9 points (depending on the number of digits in the chapter number) instead of 18, TOC 2 at 41.25, 43.75, or 45.75 instead of 42, and TOC 3 at 72 or 76.5 instead of 78. In short, I am doing everything right that I know how to do, and still Word insists on moving my tabs around to suit its whim. This problem (as well as the spaghetti-numbered outline styles and proliferating list templates) has existed in Word for at least 10 or 12 years; you would think they might have gotten around to doing something about it by now.
[ul]
[/ul]
—Dodiad
 
This problem (as well as the spaghetti-numbered outline styles and proliferating list templates) has existed in Word for at least 10 or 12 years; "

LOL. Thanks, I needed that laugh.

Gerry
 
fumei said:
dodiad said:
This problem (as well as the spaghetti-numbered outline styles and proliferating list templates) has existed in Word for at least 10 or 12 years;

LOL. Thanks, I needed that laugh.
???
[tab]
[tab]
What do you mean by this? I didn‘t know I was telling a joke. My impression is that these problems date back at least to Word 97. Is that not the case?
[tab]
—Dodiad
 
It is a sad joke. So, no, it is not really funny. I have been using Word since version 1.0 in the DOS days, and the reference to "spaghetti-numbered outline styles" made me laugh in a "I-hear-your-pain" kind of way.

Yes, these problems - or "features" if you are a Microsoft developer - go back a long way.

I certainly would not hold my breath thinking anything will change.

All in all, you appear to have made the best of things and worked out a sane (albeit probably hair-pulling) solution. Basically, I was responding/agreeing with your:

"In short, I am doing everything right that I know how to do, and still Word insists on moving my tabs around to suit its whim. "

So "its whim" and "you would think they might have gotten around to doing something about it by now"

= <laugh> I hear you!

Or put another way..."laughing and crying, it's all the same relief"

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top