![]() |
|
#6
|
||||
|
||||
|
Hi lostsoul62,
The following macro cleans up text pasted from emails, websites, etc, that insert paragraph breaks at the end of every line. Note that the code assumes there are at least two such paragraph breaks between the 'real' paragraphs. Code:
Sub CleanUpPastedText()
'Turn Off Screen Updating
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
'Eliminate spaces & tabs before paragraph breaks.
.Text = "[ ^s^t]{1,}^13"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
'Replace single paragraph breaks & line breaks with a space
.Text = "([!^13^l])([^13^l])([!^13^l])"
.Replacement.Text = "\1 \3"
'Replace all double spaces with single spaces
.Execute Replace:=wdReplaceAll
.Text = "[^s ]{2,}"
.Replacement.Text = " "
'Delete hypens in hyphenated text formerly split across lines
.Execute Replace:=wdReplaceAll
.Text = "([a-z])-[ ]{1,}([a-z])"
.Replacement.Text = "\1\2"
.Execute Replace:=wdReplaceAll
'Limit paragraph breaks & line breaks to one paragraph break per 'real' paragraph.
.Text = "[^13^l]{1,}"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
'Restore Screen Updating
Application.ScreenUpdating = True
End Sub
For Mac macro installation & usage instructions, see: http://word.mvps.org/Mac/InstallMacro.html If you'd prefer to run the macro against just a selected range, change: ActiveDocument to: Selection
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Word Empty Cells - Why is it Chr(13) & Chr(7)
|
tinfanide | Word VBA | 2 | 04-10-2012 01:34 AM |
| Apparently empty (blank) cells aren't empty | daymaker | Excel | 3 | 03-08-2012 03:41 PM |
Getting blank lines instead of supressed lines.
|
Welshie82 | Mail Merge | 2 | 11-14-2011 01:41 AM |
Empty rules
|
rene.kamphuis@ciz.nl | Mail Merge | 21 | 04-15-2011 12:34 AM |
| Populate an empty .PAB file | imported_contiw | Outlook | 2 | 08-17-2006 08:50 PM |