Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-09-25
5
Medium Priority
?
77 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 53

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 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

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 slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

670 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