Solved

Word 2010 Macro to Remove Line Numbering if Numbered

Posted on 2013-06-30
4
673 Views
Last Modified: 2013-07-02
I have a word document where some lines are numbered and some are not.  I want a macro that will move through the document paragraph by paragraph and, ONLY IF THAT LINE IS NUMBERED, set the numbering to "none" and adjust the left margin as follows:

        Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
        With Selection.ParagraphFormat
            .LeftIndent = InchesToPoints(0.19)
            .SpaceBeforeAuto = False
            .SpaceAfterAuto = False
        End With

I've attached an example word file.
WordExport.doc
0
Comment
Question by:rmbrown
[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
4 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39289163
Try this:
Public Sub RemoveNumbersFromNumberedParagraphs()
    For Each oPar In ActiveDocument.Paragraphs
        If oPar.Range.ListFormat.ListType = wdListOutlineNumbering Then
            oPar.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
            With oPar.Range.ParagraphFormat
                .LeftIndent = InchesToPoints(0.19)
                .SpaceBeforeAuto = False
                .SpaceAfterAuto = False
            End With
        End If
    Next
End Sub

Open in new window

WordExport.doc
0
 

Author Comment

by:rmbrown
ID: 39290790
Definitely answered my question so I'll accept immediately... but I have a follow on if you have time.

Regarding the indention, what I really want to do is to indent the text just enough to leave the first letter of the text in it's original location (so it looks like the number was deleted but the text didn't shift left).  What the code I sent you actually does is to move it all to the left.  When the word document is in outline form, this doesn't give me exactly what I need.

My first thought was to change the line
.LeftIndent = InchesToPoints(0.19)
to
.LeftIndent = .LeftIndent + InchesToPoints(0.19) but this results in an error since .LeftIndent surprised me by being Boolean.  Thoughts?
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39293115
Maybe the problem was that the debugger can't support .LeftIndent, you would have to include the whole expression as specified in the With statement.

But also by the time you get there the listformat has been removed and the indent changed already.

Try this:
Public Sub RemoveNumbersFromNumberedParagraphs()
    For Each oPar In ActiveDocument.Paragraphs
        If oPar.Range.ListFormat.ListType = wdListOutlineNumbering Then
            Dim intLeftIndent As Integer
            intLeftIndent = oPar.Range.ParagraphFormat.LeftIndent
            oPar.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
            With oPar.Range.ParagraphFormat
                .LeftIndent = intLeftIndent ' + InchesToPoints(0.19)
                .SpaceBeforeAuto = False
                .SpaceAfterAuto = False
            End With
        End If
    Next
End Sub

Open in new window

0
 

Author Comment

by:rmbrown
ID: 39293675
Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Suggested Courses

739 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