Solved

Creating a Table of Contents in Word Template

Posted on 2014-07-24
6
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: 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.

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

734 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