Solved

Word 2010 Macro to Remove Line Numbering if Numbered

Posted on 2013-06-30
4
644 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now