Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Word 2010 Macro to Remove Line Numbering if Numbered

Posted on 2013-06-30
4
Medium Priority
?
700 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
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

877 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