none
select line in word RRS feed

Answers

  • You don't have to select the line - you can use code like this:

        If Len(ActiveDocument.Bookmarks("\line").Range.Text) = 0 Then
            ' Current line is an empty paragraph
            ...
        Else
            ' Current line contains text
            ...
        End If


    Regards, Hans Vogelaar

    • Marked as answer by hila_d Tuesday, March 13, 2012 2:52 PM
    Monday, March 12, 2012 9:31 PM
  • Here is an example:

    Sub LoopLines()
        Dim lngStart As Long
        Dim lngPrevStart As Long
        Selection.HomeKey Unit:=wdStory
        Do
            If Len(ActiveDocument.Bookmarks("\line").Range.Text) <= 1 Then
                ' Current line is an empty paragraph
                Debug.Print "empty"
            Else
                ' Current line contains text
                Debug.Print "not empty"
            End If
            lngPrevStart = lngStart
            Selection.MoveDown
            lngStart = Selection.Start
        Loop Until lngStart = lngPrevStart
    End Sub


    Regards, Hans Vogelaar

    • Marked as answer by hila_d Tuesday, March 13, 2012 2:52 PM
    Tuesday, March 13, 2012 2:34 PM

All replies

  • Do you want to select the line containing the insertion point using VBA? If so, use

    ActiveDocument.Bookmarks("\line").Select

    Otherwise, what do you want?

    Regards, Hans Vogelaar

    Monday, March 12, 2012 5:08 PM
  • My goal is to check if my cursor line is it empty. 

    I highlight the entirerow, and then check if the low string length is zero.

    How am I do it?

    Monday, March 12, 2012 9:06 PM
  • You don't have to select the line - you can use code like this:

        If Len(ActiveDocument.Bookmarks("\line").Range.Text) = 0 Then
            ' Current line is an empty paragraph
            ...
        Else
            ' Current line contains text
            ...
        End If


    Regards, Hans Vogelaar

    • Marked as answer by hila_d Tuesday, March 13, 2012 2:52 PM
    Monday, March 12, 2012 9:31 PM
  • thank you. How am I read (with loop) any line in document?
    Tuesday, March 13, 2012 2:02 PM
  • Here is an example:

    Sub LoopLines()
        Dim lngStart As Long
        Dim lngPrevStart As Long
        Selection.HomeKey Unit:=wdStory
        Do
            If Len(ActiveDocument.Bookmarks("\line").Range.Text) <= 1 Then
                ' Current line is an empty paragraph
                Debug.Print "empty"
            Else
                ' Current line contains text
                Debug.Print "not empty"
            End If
            lngPrevStart = lngStart
            Selection.MoveDown
            lngStart = Selection.Start
        Loop Until lngStart = lngPrevStart
    End Sub


    Regards, Hans Vogelaar

    • Marked as answer by hila_d Tuesday, March 13, 2012 2:52 PM
    Tuesday, March 13, 2012 2:34 PM