Results 1 to 5 of 5
  1. #1
    JustCallMeAl
    Guest

    Testing for Beginning of Paragraph (Word97 SR2)

    Ok, multiple searches didn't bring an answer, so here goes.

    I need to test if the cursor is at the beginning of a paragraph or not. I have written some code that does just that, but I can't believe there isn't a more efficient way.

    My code:

    <pre>Set rngSelection = Selection.Range

    If rngSelection.Characters(1).Text = _
    rngSelection.Paragraphs(1).Range.Characters(1).Tex t Then .... </pre>


    Ideas?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Testing for Beginning of Paragraph (Word97 SR2)

    <pre>Function StartOPara() As Boolean
    If Selection.Type <> wdSelectionIP Then
    StartOPara = False
    ElseIf Selection.Range.Start = Selection.Paragraphs(1).Range.Start Then
    StartOPara = True
    Else
    StartOPara = False
    End If
    End Function

    Sub testfunc()
    MsgBox StartOPara()
    End Sub</pre>


    If a selection greater than an insertion point is okay, delete the first condition in the function.

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Testing for Beginning of Paragraph (Word97 SR2)

    Function StartOPara() As Boolean
    If Selection.Type <> wdSelectionIP Then
    StartOPara = False
    Else
    with Selection
    StartOPara = (.Range.Start = .Pagraphs(1).Range.Start)
    end with
    End If

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Testing for Beginning of Paragraph (Word97 SR2)

    Nice! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

  5. #5
    JustCallMeAl
    Guest

    Re: Testing for Beginning of Paragraph (Word97 SR2)

    Thanks all.

Posting Permissions

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