Consulting

Results 1 to 3 of 3

Thread: Selecting/Highlighting all blank lines in Word 2011

  1. #1
    VBAX Newbie
    Joined
    Sep 2020
    Posts
    2
    Location

    Selecting/Highlighting all blank lines in Word 2011

    I'm trying to find a way (may be with a macro) to select and highlight all the blank lines (rows) in a Word 2011 file.
    My file usually start off with text on every second line with a blank line in between. Each line, text or blank is ended with a RETURN. My goal is to select all the blank lines all at once before applying a custom style to them. So far I've been Command + Click (Mac) each line, one at a time until all of them are selected/highlighted. The problem is my file could be few pages long with hundreds of blank lines to click. That's why I'm hoping if someone can come up with a quicker, maybe a one-click solution to speed up this process. Any suggestions will be greatly appreciated.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Word VBA does not support select non-contiguous ranges like you can with the user interface. However, you can loop through the paragraphs (lines as you call them) and set a style:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oPar As Paragraph
      For Each oPar In ActiveDocument.Range.Paragraphs
        If Len(oPar.Range.Text) = 1 Then
          oPar.Style = "Heading 1"
        End If
      Next oPar
    lbl_Exit:
      Exit Sub
    End Sub
    What is the point of an empty paragraph (line) with a style? In practice, you should avoid empty paragraphs with Word. Use space before or after the paragraphs that have text.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Sep 2020
    Posts
    2
    Location
    Quote Originally Posted by gmaxey View Post
    Word VBA does not support select non-contiguous ranges like you can with the user interface. However, you can loop through the paragraphs (lines as you call them) and set a style:

    Sub ScratchMacro()
    'A basic Word macro coded by Greg Maxey
    Dim oPar As Paragraph
      For Each oPar In ActiveDocument.Range.Paragraphs
        If Len(oPar.Range.Text) = 1 Then
          oPar.Style = "Heading 1"
        End If
      Next oPar
    lbl_Exit:
      Exit Sub
    End Sub
    What is the point of an empty paragraph (line) with a style? In practice, you should avoid empty paragraphs with Word. Use space before or after the paragraphs that have text.


    In case you're wondering what I'm trying to do here. I'm preparing songs sheets for a group of beginners with lyrics and guitar chords just above each line of lyrics. After placing the lyrics of a song on every second line, I'd like to format the blank line above the lyric to a certain (different) style before adding the chords. That way I can add and/or modify the chords later without affecting the lyrics. So in order to do that, I would manually select (command + click with a Mac) on every blank line within the whole document before applying the custom style to all the blank lines prior to adding chords. Sometimes the song can be 2-3 pages long, meaning a lot of command-clicking between all the blank lines… I was just trying to look for an easier way to select and highlight them all at once before continue on. I hope that explains a bit better what I'm doing here.

Posting Permissions

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