Solved

Creating a Table of Contents in Word Template

Posted on 2014-07-24
6
290 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

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…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
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 …

809 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