Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Sydney Australia
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is paragraph empty? (Windows 2000)

    How do I test a paragraph to determine whether it is empty or contains some (any) characters?

    Without moving the cursor, I want to be able to:

    Count characters

    Then...

    If number is > 0 Then move cursor to start of paragraph

    EndIf

    Continue...

    Thanks in advance for any suggestions

    PeteF

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Is paragraph empty? (Windows 2000)

    Someone will probably come up with a simple one liner, but this works for me...
    <pre>Selection.paragraphs(1).Range.Select
    Selection.Collapse direction:=wdcollapsestart
    </pre>

    You don't need to check for an empty paragraph first, but If you want to then enclose it in
    <pre>If Selection.Paragraphs(1).Range.Characters.Count > 1 Then
    <font color=448800> 'put your code here </font color=448800>
    End If
    </pre>

    StuartR

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Is paragraph empty? (Windows 2000)

    You can use Selection.Paragraphs(1).Range.Characters.Count to find the number of characters in the first paragraph in the current selection (if you see the blinking vertical bar, the selection is the insertion point). In Word, an "empty" paragraph contains just the paragraph marker, so the character count is 1, not 0. Try the following:

    If Selection.Paragraphs(1).Range.Characters.Count > 1 Then
    Selection.MoveUp Unit:=wdParagraph
    End If

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Is paragraph empty? (Windows 2000)

    If the beginning of the current selection is already at the beginning of the paragraph then this code will move the insertion point to the beginning of the previous paragraph. This may not matter to the original poster, depending on how they get to this situation.

    StuartR

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Is paragraph empty? (Windows 2000)

    <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Is paragraph empty? (Windows 2000)

    How about...
    <pre>If Selection.Range.Start > Selection.Paragraphs(1).Range.Start Then
    Selection.MoveUp Unit:=wdParagraph
    End If
    </pre>


    This will only move the cursor if it is not at the beginning of a paragraph, the empty paragraph is a special case of "current selection is at the beginning of the paragraph", so it is left alone.

    What behaviour do you want if the selection includes the beginning of the paragraph and a few more characters, my first post will reduce it to a point at the beginning, this one will leave it alone.

    StuartR

  7. #7
    New Lounger
    Join Date
    Mar 2002
    Location
    Sydney Australia
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Is paragraph empty? (Windows 2000)

    StuartR and HansV

    This one works the best. All the others seemed to have an exception depending on the location of the paragraph when in a table cell and the various options in my macro. I haven't tested exhaustively, but think this one is a goer.

    Yes you are right Stuart, it was important not to have the cursor moving up to the previous paragraph, because a text insertion is the next step in the macro.

    I extend my thanks to both of you for your generous assistance

    PeteF

Posting Permissions

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