Solved

How to mark a lot of lines for table of content headings in Word 2010?

Posted on 2016-09-25
5
70 Views
Last Modified: 2016-10-02
I want to mark all the lines in a selected area in a Word 2010 file as table of content level 2.

All the lines start with Sub and end with ().

For example: Sub TestAboveAverage()
0
Comment
Question by:Alex Campbell
[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
  • 2
  • 2
5 Comments
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41815736
Hi,
You could use find and replace
Find What
Sub*\(\)
Options Wildcard
Replace with
^&
Format Style TOC 2

Regards
0
 
LVL 31

Expert Comment

by:Helen Feddema
ID: 41820489
I have a Word template that formats code (including a special style for the Sub and End Sub lines).  You may find it useful.  Just highlight a chunk of code, open an instance of the template and click OK on the question about pasting the code in, then run the FormatCode macro (I put in on the QAT for handy reference).  

EE won't upload .dotm files, so I renamed it with the .dot extension -- just rename it with the .dotm extension before using it.
Code.dot
0
 
LVL 1

Author Comment

by:Alex Campbell
ID: 41824958
I have tried to both methods and while I appreciate the work, I have tried both and I didn't get the result I was looking for. I was thinking more of a macro that would:
1) Find each line beginning the Sub
2) Select from the begin of the line to the end
3) Mark style as TOC 2.
0
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41825563
then try
Sub macro()

For Each par In ActiveDocument.Range.Paragraphs
    If par Like "Sub*" Then
        par.Style = ActiveDocument.Styles("TOC 2")
    End If
Next
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:Alex Campbell
ID: 41825724
That did it. Great, thanks!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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.

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