• Easy Question: Insertion Point Test

    • This topic has 2 replies, 3 voices, and was last updated 24 years ago.
    Author
    Topic
    #353871

    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!

    Viewing 1 reply thread
    Author
    Replies
    • #518653

      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

    • #518656

      Here’s one way to do it:

      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
      

      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.

    Viewing 1 reply thread
    Reply To: Easy Question: Insertion Point Test

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: