Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post

    Number Paragraphs in a Document

    Hello folks,

    hope everyone is doing great.

    I have got stuck on this assuming a should be not so difficult task.

    My goal is to number paragraphs in a document. Excluding the empty paragraphs.

    So far I have

    Code:
    Sub NumberParagraphs()
    
     
      Dim pNumber As Long
      Dim i As Long
      pNumber = 100   'Starting number
    
       Dim oPara As Word.Paragraph
       For Each oPara In ActiveDocument.Paragraphs
       
        oPara.Range.InsertBefore "P - " & pNumber
        Next oPara
        pNumber = pNumber + 1
      
    End Sub
    I am not sure how to continue, google not showing anything useful. I know i have missed maybe a with statement

    thanks for your advice

    pb

  2. #2
    Silver Lounger
    Join Date
    Mar 2014
    Location
    Forever West
    Posts
    2,072
    Thanks
    0
    Thanked 259 Times in 248 Posts
    Word 2010 Help for numbered paragraphs brings up a long list but I've included only what works for me:

    Create a bulleted or numbered list

    You can quickly add bullets or numbers to existing lines of text, or Word can automatically create lists as you type.

    By default, if you start a paragraph with an asterisk or a number 1., Word recognizes that you are trying to start a bulleted or numbered list. If you don't want your text turned into a list, you can click the AutoCorrect Options button Button image that appears.
    Note: you can create what would be an "empty Paragraph" by hitting Enter at the end of a paragraph. After seeing a number with no text following and hitting Enter, the next number will be assigned to the next paragraph.

  3. #3
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    hi Berton,

    thanks for tip.

    I am trying to manually insert numbers. These are kind of like placeholder identifiers.

    Each document would have a different set of paragraph Numbers.

    Example
    P200 Video provides a powerful way to help you prove your point. When you click Online
    P201 Video provides a powerful way to help you prove your point. When you click Online
    etc

    I need to insert numbers before each paragraph.

    I know what you mean about lists but these paragraphs are separated, not sure if i can number them that way the built in way?

    pb

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    A: You should not have empty paragraphs. If you need extra space between paragraphs, that should be managed via the paragraph before/after space settings.
    B: Having deleted the empty paragraphs (which you can do via Find/Replace), you can then use auto-numbering.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    Silver Lounger
    Join Date
    Mar 2014
    Location
    Forever West
    Posts
    2,072
    Thanks
    0
    Thanked 259 Times in 248 Posts
    I did as that Help suggested just before I posted. When starting with 1. then putting the cursor at the end of each paragraph pressing Enter puts a number at the beginning of the next text. If it's a blank line it gets numbered just as if it's a blank paragraph and the following numbered paragraph is moved down.
    Example of how it looked:

    1. Now is the time

    2.

    3. Then was the time

  6. #6
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Thank you Paul and Berton,

    Paul reminded me of a good point - I shouldn't have empty paragraphs - will write a quick macro for that

    I was actually thinking the same thing today, increasing the padding around the paragraphs.

    Word is very advanced - there are still so many functions i have not been exposed to.

    Ok the paragraph numbering works so that will be suffice, I can start from 300 or whatever number I choose.

    thanks gentlemen

    Good day to all

    pb

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Quote Originally Posted by pb89 View Post
    I shouldn't have empty paragraphs - will write a quick macro for that
    You don't need a macro, just a single wildcard Find/Replace, where:
    Find = [^13]{2,}
    Replace = ^p
    Quote Originally Posted by pb89 View Post
    I was actually thinking the same thing today, increasing the padding around the paragraphs.
    The preferred way of doing that is by modifying the relevant Style definitions, but you can also do it by selecting a range and using the paragraph formatting tools.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. The Following 2 Users Say Thank You to macropod For This Useful Post:

    Charles Kenyon (2016-04-30),pb89 (2016-04-30)

  9. #8
    Star Lounger
    Join Date
    Jan 2016
    Posts
    77
    Thanks
    18
    Thanked 1 Time in 1 Post
    Cheers Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •