PDA

View Full Version : Selecting/Highlighting all blank lines in Word 2011



uhjb
09-06-2020, 11:34 PM
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.

gmaxey
09-08-2020, 10:08 AM
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.

uhjb
09-08-2020, 01:54 PM
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.