Solved

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

Posted on 2016-09-25
5
63 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:Alex972
  • 2
  • 2
5 Comments
 
LVL 49

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:Alex972
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 49

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:Alex972
ID: 41825724
That did it. Great, thanks!
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

770 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