Searching for blank lines in Heading 1

S

Steve Wylie

I need a short macro that will cycle through a document looking for empty
paragraphs that are in Heading 1, ie they contain a paragraph break in
Heading 1 but no actual text within the paragraph.

I want it to skip past any paragraph in Heading 1 that contains text, but
just stop at any it finds that are in Heading 1, but empty.

Thanks for any help anyone can give!

Steve Wylie
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Steve,

Why stop at removing the blank lines from Heading 1?

However, this code should do it:

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^p^p", Wrap:=wdFindStop, Forward:=True)
= True
If Selection.Range.Style = "Heading 1" Then
Selection.Range.Text = Left(Selection.Range.Text, 1)
Selection.Range.Style = "Heading 1"
End If

Loop
End With

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
S

Steve Wylie

Thanks Doug. I've had a go at your macro, but it stops with an error upon
finding a blank Heading 1 on my Word 2000, and also upon finding a valid
Heading 1 with text in. "Object variable or With block variable not set",
it says. Do you know why?

Steve
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Steve,

What line of the macro is highlighted when the error occurs?

Send me a copy of the document if you wish and I will try and sort it out.
Sent it to dkr<atsign>mvps.org

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Steve,

It might be splitting hairs, but in the document that you sent to me, there
were no blank lines in the Heading 1 paragraphs. The blank lines were in
paragraphs to which the Normal style was applied.

To get rid of them, you should use a Wildcard Replace with ^13{1,} in the
Find what control and ^p in the Replace with control.

See the article “Finding and replacing characters using wildcards” at:

http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
S

Steve Wylie

Hello again
Heading 1 paragraphs. The blank lines were in paragraphs to which the
Normal style was applied

I think you'll find line 8 of the document has a blank line in Heading 1.
Find what control and ^p in the Replace with control.

The trouble is that in the documents that I use at work (a template for
Minutes of meetings), blank lines are achieved by pressing Return twice,
like a typist would, rather than using paragraph spacing as you should.
Don't ask me - I didn't set it up and the people that did are adamant that
it stays like this!

Occasionally you get what should be a normal paragraph (in a style called
"Body") appearing in the Heading 1 style. The only thing I can do at the
moment is to click on the Document map and select "Show Heading 1's only"
and manually check down the pages to see if any blank lines appear rather
than headings in paragraphs formatted with Heading 1 style.

So what I need, unlikely as it may seem, is a macro that checks for lines
that are in Heading 1 but contain no text. As far as I can see, the
wildcard search you suggested would replace every return on every line, even
the genuine headings.

Can what I need be done with a macro, or a wildcard search? Isn't there a
funny wildcard symbol for searching for a ^13 or ^p which is at the
beginning of a line (hence, there's no text)? My wildcard search knowledge
isn't all that good, but I'm sure I've seen something done before that used
that technique.

Steve
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Steve,

I would suggest that you modify the template so that empty lines are created
by having a space after or before the paragraphs.

However, the following modified macro will do what you want.

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="^p", Wrap:=wdFindStop, Forward:=True) =
True
If Selection.Range.Style = "Heading 1" And
Len(Selection.Range.Paragraphs(1).Range) = 1 Then
Selection.Delete
End If
Loop
End With

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
K

Klaus Linke

Can what I need be done with a macro, or a wildcard search?
Isn't there a funny wildcard symbol for searching for a ^13
or ^p which is at the beginning of a line (hence, there's no text)?


Hi Steve,

"Paragraph anchors" that match the start and end of a paragraph (similar to
the word anchors < and > ) are a feature that I've seen requested quite a
bit.
You can add your vote in an email to (e-mail address removed).

As it is, there's no way to find empty lines with a single search.

Doug has already given you a macro solution as an alternative to wildcard
replacements.

You could get rid of empty "Heading 1" paragraphs in more than one
Replacement in a number of ways.
One would be to replace all non-empty "H 1" paragraphs with some paragraph
formatting such as "right-aligned":

Find what: [!^13]@^13 ((+ Format > Style > Heading 1))
Replace with: ^& ((+ Format > Paragraph > Alignment > Right))

Then delete all remaining (empty) left-aligned "Heading 1" paragraphs:
No wildcards,
Find what: ((leave empty,
Format > Style=Heading 1 +
Format > Paragraph > Alignment=Left))
Replace with: ((leave empty to delete))

Then left-align the "Heading 1" paragraphs with another non-wildcard
"Find/Replace".
Find what: ((Heading 1, Alignment=Right))
Replace with: ((Alignment=Left))

Pretty clumsy... But if you use the shortcuts Ctrl+L and Ctrl+R in the
"Find/Replace" dialog, it's not too bad.
And if you record it as a macro, you'll only have to do it once.

Klaus
 
S

Steve Wylie

Thanks Klaus - but I think I'll stick with Doug's macro approach! I must
have been confusing the < and > wildcard features used on words and thinking
you could apply them to whole paragraphs too, which obviously you can't.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top