![]() |
|
|
|
#1
|
||||
|
||||
|
Hi Mark,
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 with a space
.Text = "([!^13])([^13])([!^13])"
.Replacement.Text = "\1 \3"
'Replace all double spaces with single spaces
.Execute Replace:=wdReplaceAll
.Text = "[ ]{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 to one per 'real' paragraph.
.Text = "[^13]{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] |
|
#2
|
|||
|
|||
|
I've been saying (mainly to myself) that "someone must have written a macro..."
and here it is!! Thanks so much, and also thanks for the instruction on how to do a selection rather than the whole document which will be better for my use. Pasting text from a pdf file into word comes in with a CR at the end of every line...very aggravating. I would have thought that if one dragged/dropped a pdf file into Word that it would automatically format it, but no such luck, apparently. Thanks SO MUCH |
|
#3
|
|||
|
|||
|
see my previous reply too
More in the "curiosity" area is the following: I did a copy and paste of this, pasting it into the normal template but changed the name from yours to "xtracr" (extra carriage returns) and also the change you recommended for doing a "selection" rather than "active document". I made no other changes AT ALL. The first time I tried running the macro it wouldn't work. Then it did work one or two times, and then failed to work at all (with my new name). In a "just for the heck of it" vein, I went back to your original name and it's worked fine ever since. Is it possible that your name for this macro is hidden somewhere else in the coding? Doesn't seem possible to me, but my coding days are far behind me.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Hard space in justified text
|
czytajsk | Word | 6 | 06-27-2012 05:03 PM |
| Saving Emails to my Local Hard Drive | MichaelWaite | Outlook | 1 | 02-08-2012 06:53 AM |
| IF formula returns TRUE instead of evaluating COUNTIF | ColinC | Excel | 4 | 12-28-2011 08:21 AM |
Access pst files on external hard drive
|
LOUDONCLEAR | Outlook | 1 | 09-22-2011 06:13 PM |
| New Hard Drive | abatson1995 | Office | 0 | 12-25-2009 02:13 PM |