Solved

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

Posted on 2016-09-25
5
46 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 48

Expert Comment

by:Rgonzo1971
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Alex972
Comment Utility
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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:Alex972
Comment Utility
That did it. Great, thanks!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now