Solved

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

Posted on 2016-09-25
5
67 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
[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: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 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:Alex972
ID: 41825724
That did it. Great, thanks!
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

My experience with Windows 10 over a one year period and suggestions for smooth operation
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.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

737 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