Stop removing blank lines at the end of a document

F

Felix

Hello,

I have a series of rather large Word documents used in testing. Once testing
is complete, I clean up the documents to remove the testing bits (checkboxes,
approvals and such) and then compile the document in chm form to be used as a
help file.

I've written a macro that cleans up the document by selectively removing
some table rows, and some "This page is intentionally blank" entries. I would
also like to remove a whole lot of unnecessary blank lines, but only starting
at a certain point in the document.

So, I need to first move to the point in the document where I want to begin
removing blank lines, then start removing blank lines (including those with
spaces), and then stop once I reach the end of the document.

Any help is greatly appreciated.
 
M

macropod

Hi Felix,

Try the following macro with the insertion point positioned where you want the clean-up to start:
Sub Cleanup()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([ ]{1,})([^13])"
.Replacement.Text = "\2"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
.Text = "([^13])([^13]{1,})"
.Replacement.Text = "\1"
.Execute Replace:=wdReplaceAll
End With
End Sub
 
F

Felix

Thanks. This didn't quite give me the expected results. It didn't go through
the entire document, and it affected my formatting somewhat. In some cases,
it wiould delete a blank line just before a line formatted with a header
style, which causes the header to lose it's style (can't figure that one out).

I'm wondering if the presence of multiple tables might be the cause...

macropod said:
Hi Felix,

Try the following macro with the insertion point positioned where you want the clean-up to start:
Sub Cleanup()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([ ]{1,})([^13])"
.Replacement.Text = "\2"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
.Text = "([^13])([^13]{1,})"
.Replacement.Text = "\1"
.Execute Replace:=wdReplaceAll
End With
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


Felix said:
Hello,

I have a series of rather large Word documents used in testing. Once testing
is complete, I clean up the documents to remove the testing bits (checkboxes,
approvals and such) and then compile the document in chm form to be used as a
help file.

I've written a macro that cleans up the document by selectively removing
some table rows, and some "This page is intentionally blank" entries. I would
also like to remove a whole lot of unnecessary blank lines, but only starting
at a certain point in the document.

So, I need to first move to the point in the document where I want to begin
removing blank lines, then start removing blank lines (including those with
spaces), and then stop once I reach the end of the document.

Any help is greatly appreciated.
.
 
F

Fumei2 via OfficeKB.com

"It didn't go through the entire document"

Of course it did not go through the entire document. That is because you
asked for:

"So, I need to first move to the point in the document where I want to begin
removing blank lines,"

Which macropod gave you, and stated:

"Try the following macro with the insertion point positioned where you want
the clean-up to start:"


Your fomrat issues may come from your use of the word "line". Do you mean
paragraph? Why are there "blank" lines? And are you saying there are
paragraphs with only spaces?


Thanks. This didn't quite give me the expected results. It didn't go through
the entire document, and it affected my formatting somewhat. In some cases,
it wiould delete a blank line just before a line formatted with a header
style, which causes the header to lose it's style (can't figure that one out).

I'm wondering if the presence of multiple tables might be the cause...
Hi Felix,
[quoted text clipped - 38 lines]
 

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