Solved

Word 2010 Macro to Remove Line Numbering if Numbered

Posted on 2013-06-30
4
656 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 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
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.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

810 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