Hi Joan,
Here is a macro I use for doing just what you inquire about (written with
VBA 2003--though there is nothing in it that is specific to that release).
Since there is usually some ambiguity as to whether the return should be
deleted or replaced with a space, the macro queries this point (though it
doesn't offer the two options--which could easily be changed [for my
purposes, not offering the option has more to do with those running the macro
than the difficulty in coding]). It also uses "selection" which many on here
will caution against. Since the macro stops at every successful match, speed
is not really an issue. If you want to do away with the queries and let the
macro just strip and replace as it deems necessary, comment out the query
"if" statement. I would NOT recommend doing this. WARNING: this macro does
not find every errant return. You will still have to QC the doc. It does,
however, find most of them. You may want to consider something that looks for
alternate ways of breaking lines (soft return, page break, section break,
etc.) and converts them to regular hard returns (depending upon whether or
not you want to preserve the page and section breaks--I do not). The basic
method shown here could be expanded to include a lot more cases.
Sub CleanupExtraParas()
Selection.HomeKey Unit:=wdStory
Dim x As Integer
x = 0
Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = ",^p"
.Replacement.Text = ", "
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
If MsgBox("Should this hard return be replaced with a space?",
vbQuestion + vbYesNo) = vbYes Then
Selection.Delete
Selection.InsertBefore (", ")
End If
Else
x = 1
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Loop Until x = 1
Selection.HomeKey Unit:=wdStory
x = 0
Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = "([a-z])^13([a-z])"
.Replacement.Text = "\1 \2"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If MsgBox("Should this hard return be replaced with a space?",
vbQuestion + vbYesNo) = vbYes Then
Selection.Delete
Selection.InsertBefore (" ")
End If
Else
x = 1
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Loop Until x = 1
Selection.HomeKey Unit:=wdStory
x = 0
Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = "([-])^13([a-z])"
.Replacement.Text = "\1 \2"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If MsgBox("Should this hard return be deleted?", vbQuestion +
vbYesNo) = vbYes Then
Selection.Delete
'Selection.InsertBefore (" ")
End If
Else
x = 1
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Loop Until x = 1
Selection.HomeKey Unit:=wdStory
x = 0
Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = "([a-z] )^13([a-z])"
.Replacement.Text = "\1\2"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If MsgBox("Should this hard return be deleted?", vbQuestion +
vbYesNo) = vbYes Then
Selection.Delete
'Selection.InsertBefore (" ")
End If
Else
x = 1
End If
Selection.MoveRight Unit:=wdCharacter, Count:=1
Loop Until x = 1
End Sub
HTH,
jalanford
Joan NYC said:
I have tried to do this with Pattern Matching to no avail
I am working on a job which entails reformatting some horribly formatted docs
I spent lots of time stripping out the hard returns manually
Everyone who worked on this mess didn't know about Paragraph formatting and
just kept pressing "return" which drives me crazy
Any suggestions would be appreciated
BTW, this is Word 2003 and I still cannot write code (I have tried!)