Hi
I must be doing something stupid here - can't figure out why it is not replacing two paragraph marks with one. It *finds* the two paragraphs if I find one at a time but it *doesn't* replace.
A process creates a Word document where most paragraphs have an extra blank paragraph at the end. Now, I am trying to remove these blank paragraphs but the Find & Replace doesn't work.
A sample word document is attached.
Thanks.
replace two paragraph markers with one
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
replace two paragraph markers with one
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78917
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: replace two paragraph markers with one
The second paragraph mark of each pair is different - it has extra properties in the XML code that makes it behave differently. But I can't find what exactly.
Here is a workaround:
- Enter ^p in the 'Find what' box and @@@ in the 'Replace with' box, then click 'Replace All'.
- Only the first paragraph mark in each pair will be replaced.
- Enter @@@ in the 'Find what' box and clear the 'Replace with' box, then click 'Replace All'.
Here is a workaround:
- Enter ^p in the 'Find what' box and @@@ in the 'Replace with' box, then click 'Replace All'.
- Only the first paragraph mark in each pair will be replaced.
- Enter @@@ in the 'Find what' box and clear the 'Replace with' box, then click 'Replace All'.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 656
- Joined: 18 Feb 2010, 14:26
Re: replace two paragraph markers with one
Thanks Hans, I will try that.HansV wrote:The second paragraph mark of each pair is different - it has extra properties in the XML code that makes it behave differently. But I can't find what exactly.
Here is a workaround:
- Enter ^p in the 'Find what' box and @@@ in the 'Replace with' box, then click 'Replace All'.
- Only the first paragraph mark in each pair will be replaced.
- Enter @@@ in the 'Find what' box and clear the 'Replace with' box, then click 'Replace All'.
Also, I have just found out that these documents are created using HTML/XML (not sure which one).
-
- PlutoniumLounger
- Posts: 15810
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: replace two paragraph markers with one
Hi Robie, and I see Hans's reply.Robie wrote:I must be doing something stupid here -...
You are not stupid (apart from the fact that you are using MSWord, that is
![Laugh :laugh:](./images/smilies/laugh.gif)
![Clapping :clapping:](./images/smilies/clapping.gif)
I have had the same problem writing VBA code/macros to remove excess white space since at least Word97.
(I am now at Word2003, and starting to give up hope
![ROFL :rofl:](./images/smilies/rofl.gif)
Cheers
Chris
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: replace two paragraph markers with one
For whatever reason, Word refuses to find & replace a paragraph break that precedes a table. This is a long-standing bug. You could achieve the desired outcome with a macro like:
The 'wdReplaceAll' reduces all consecutive paragraph breaks other than before a table to single paragraph breaks; the loop handles those before tables.
Code: Select all
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "[^13]{2,}"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
.Wrap = wdFindStop
.Execute
End With
Do While .Find.Found
.End = .End - 1
.Text = vbNullString
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- BronzeLounger
- Posts: 1545
- Joined: 26 Jan 2010, 11:36
- Location: Melbourne, Australia
Re: replace two paragraph markers with one
Just out of curiosity, would it be possible to firstly replace all ^13 instances with ^p, then run the usual search/replace of ^p^p with a single^p? I mean from the UI dialog, rather than from Macropod's macro.
Alan
Alan
-
- 4StarLounger
- Posts: 508
- Joined: 17 Dec 2010, 03:14
Re: replace two paragraph markers with one
Using ^13 makes no difference.
Paul Edstein
[Fmr MS MVP - Word]
[Fmr MS MVP - Word]
-
- BronzeLounger
- Posts: 1545
- Joined: 26 Jan 2010, 11:36
- Location: Melbourne, Australia
Re: replace two paragraph markers with one
Yes, I can see the bug when I try it on the sample docx. Most peculiar. Then again, I can also see why there is a need to retain the ^p immediately preceding a table.
Alan
Alan