Solved

Creating a Table of Contents in Word Template

Posted on 2014-07-24
6
284 Views
Last Modified: 2014-07-25
I have created a template with a bunch of Rich Text Controls. I am trying to create a Table of Contents for this document but the Table of Contents always contains the words in the Controls, like "Click here to enter text". How do I get rid of that verbiage in my Table of Contents?
0
Comment
Question by:manndo
  • 3
  • 2
6 Comments
 
LVL 31

Expert Comment

by:Paul Sauvé
ID: 40218421
Hi manndo

I have created a template with a bunch of Rich Text Controls. I am trying to create a Table of Contents for this document but the Table of Contents always contains the words in the Controls, like "Click here to enter text"
Are you simply trying to predefine your ToC styles? Can you post a copy of your template?

Thanks, PaulSauve
0
 

Author Comment

by:manndo
ID: 40218435
Here is a little of the template. When I create a Table of Contents from this template, it includes the words "Click here to enter text".

This is the template portion: The "Click here to enter text" is a Rich Text field on the template for typing in information.

12.      Removing Subjects from Study
12.1.      Criteria: Click here to enter text.
12.2.      Treatment failure: Click here to enter text.
12.3.      Documentation of early subject removal: Click here to enter text.
12.4.      Procedure for subjects who withdrawal early: Click here to enter text.
12.5.      Replacement of removed subjects: Click here to enter text.



This is the Table of Contents that is auto-generated:

12.      Removing Subjects from Study      ii
12.1.      Criteria: Click here to enter text.      ii
12.2.      Treatment failure: Click here to enter text.      ii
12.3.      Documentation of early subject removal: Click here to enter text.      ii
12.4.      Procedure for subjects who withdrawal early: Click here to enter text.      ii
12.5.      Replacement of removed subjects: Click here to enter text.      ii

So I want the doc to be a template but then then Table of Contents should only show:

12. Removing Subjects from Study...................................ii
12.1 Criteria:...................................................................... ii
12.2 Treatment Failure:.....................................................ii

How do I keep it from adding that extra text. Even if I delete it all after the Table of Contents is created, if I update the table it will come right back.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 40218786
The placeholder text can also look anomalous on a printed document.

You can do a find and replace on the TOC after it is created or updated. Here is a macro that you might find useful if you have to do it frequently.
Sub EditToc()
    Dim toc As TableOfContents
    Set toc = ActiveDocument.TablesOfContents(1)
    With toc.Range.Find
        .Text = "Click here to enter text"
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:manndo
ID: 40219213
Yes. Manually, this is what I've been doing but this Template is constantly updated so the find and replace must be done all the time really (every time something is added to the document. Can you explain to me how to put this macro in place in my document and will it work without me having to run it? Also, I should say that obviously I do not want to replace the actual template "insert rich text fields" that say "Click here to enter text" - just the ones that appear in the Table of Contents. Doesn't it seem like Microsoft would have a better solution for this? I mean I am sure that people create templates with Table of Contents all the time, so it seems like the programming would be written to understand that those text fields should not appear in the Table of Contents. I have tried to select (highlight) just the words that should be used all through the document and manually marking them as a level in the Table of Contents. Still, no dice.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 40219687
If a macro has the same name as a Word command, it will run instead of the command. You can put this version in a module of the template. It will run when the Update Table button is clicked. The code first does the job that the command would have done and then runs the replace code.
Sub UpdateTableOfContents()
    Dim toc As TableOfContents
    
    Set toc = ActiveDocument.TablesOfContents(1)
    toc.Update
    With toc.Range.Find
        .Text = "Click here to enter text"
        .Execute Replace:=wdReplaceAll
    End With

End Sub

Open in new window

0
 

Author Closing Comment

by:manndo
ID: 40220050
OMGosh! It worked. You are a genius GrahamSkan. Thank you so much.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you work with Word a lot, you probably use styles. If you use styles a lot, you've probably balled your fist more often than not when working with the ribbon. In Word 2007/2010, one of the things that I find missing when using styles is a quic…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now