Solved

Creating a Table of Contents in Word Template

Posted on 2014-07-24
6
292 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 32

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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

756 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