Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jan 2001
    Location
    Lafayette, Indiana, USA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Easy Question: Insertion Point Test

    Here's two easy questions from a VBA newbie:

    I have a paragraph of text in a Word document. Using VBA,

    1) How can I test whether the insertion point is at the start of the paragraph?

    2) How can I test whether the insertion point is at the end of the paragraph?

    Thanks for your help!

  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Easy Question: Insertion Point Test

    Poking around in Steve Roman's Writing Word Macros there's StartOf and EndOf methods of the selection and range objects. It mentions that the StartOf method returns zero if you are already at the start of the range of selection.

    I don't know if this helps.

    Mike

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

    Re: Easy Question: Insertion Point Test

    Here's one way to do it:

    <pre>Sub IsInsertionPointAtStartOrEndOfParagraph()
    Dim rngCurPara As Range
    Dim lngSelStart As Long
    If Selection.Type = wdSelectionIP Then
    Set rngCurPara = Selection.Paragraphs(1).Range
    lngSelStart = Selection.Start
    If lngSelStart = rngCurPara.Start Then
    MsgBox "Insertion point is at start of Paragraph "
    End If
    If lngSelStart = rngCurPara.End - 1 Then
    MsgBox "Insertion point is at end of paragraph "
    End If
    End If
    End Sub
    </pre>

    BTW to use the preformatted code that appears here: copy it, paste it into the body of a Word document, then copy it again and finally paste it into your VB Editor.

Posting Permissions

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