Answered select line in word

  • Monday, March 12, 2012 4:38 PM
     
     

    How am I select line in word?

All Replies

  • Monday, March 12, 2012 5:08 PM
     
      Has Code

    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 9:06 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:31 PM
     
     Answered Has Code

    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
    •  
  • Tuesday, March 13, 2012 2:02 PM
     
     
    thank you. How am I read (with loop) any line in document?
  • Tuesday, March 13, 2012 2:34 PM
     
     Answered Has Code

    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
    •