Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating a Table of Contents in Word Template

Posted on 2014-07-24
6
Medium Priority
?
302 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 33

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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

963 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