Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 02-06-2016, 02:09 PM
macropod's Avatar
macropod macropod is offline Cleaning up Text Pasted from Websites, E-mails, PDFs etc. Windows 7 64bit Cleaning up Text Pasted from Websites, E-mails, PDFs etc. Office 2010 32bit
Administrator
Cleaning up Text Pasted from Websites, E-mails, PDFs etc.
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,702
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default Cleaning up Text Pasted from Websites, E-mails, PDFs etc.

When you paste text from a PDF, web site or an email, you may end up with a paragraph break at the end of every line within a logical paragraph, and two such breaks between logical paragraphs. Such text stubbornly refuses to honour justification, for example, because there's nothing to justify - it's all a series of one-line paragraphs. You should be able to see this if you have Word configured to display formatting marks on-screen. Clicking the symbol on the toolbar/home tab toggles this on/off.

The following series of wildcard Find/Replace actions cleans up text pasted from emails, websites, etc., that insert paragraph breaks at the end of every line. Note also that the process assumes there are at least two such paragraph breaks between the 'real' paragraphs.

To do a wildcard Find/Replace, open the Find/Replace dialogue, then click 'More' and click on the 'use wildcards' option.

Find = [ ^s^t]{1,}^13
Replace = ^p
Find = ([!^13^l])([^13^l])([!^13^l])
Replace = \1 \3


Find = [^s ]{2,}
Replace = ^32
Find = ([a-z])-[ ^s]{1,}([a-z])
Replace = \1\2
Find = [^13^l]{1,}
Replace = ^p

Note: Depending on your system's regional settings, you may need to replace all the commas in the above Find/Replace expressions with semi-colons. For example:
[ ^s^t]{1,}^13
becomes:
[ ^s^t]{1;}^13

The following macro automates the above Find/Replace sequence, as well as dealing with any internationalisation issues.
Code:
Sub CleanUpPastedText()
'Turn Off Screen Updating
Application.ScreenUpdating = False
Dim StrFR As String, i As Long
'Paired F/R expressions, each separated by |
StrFR = "[ ^s^t]{1,}^13|^p|([!^13^l])([^13^l])([!^13^l])|\1 \3|[^s ]{2,}| |([a-z])-[^s ]{1,}([a-z])|\1\2|[^13^l]{1,}|^p"
'Address any Internationalisation issues
If Application.International(wdListSeparator) = ";" Then
  StrFR = Replace(StrFR, ",", ";")
End If
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Forward = True
  .Wrap = wdFindStop
  .Format = False
  .MatchAllWordForms = False
  .MatchSoundsLike = False
  .MatchWildcards = True
  'Process all F/R expressions
  For i = 0 To UBound(Split(StrFR, "|")) Step 2
    .Text = Split(StrFR, "|")(i)
    .Replacement.Text = Split(StrFR, "|")(i + 1)
    .Execute Replace:=wdReplaceAll
  Next
End With
'Restore Screen Updating
Application.ScreenUpdating = True
End Sub
For PC macro installation & usage instructions, see: Installing Macros
For Mac macro installation & usage instructions, see: Word:mac - Install a Macro

If you'd prefer to run the macro against just a selected range, change:
ActiveDocument
to:
Selection
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cleaning up Text Pasted from Websites, E-mails, PDFs etc. Unable to download Microsoft Office 2010 after cleaning system Warxfreedom Office 3 01-15-2016 11:26 PM
Cleaning up Text Pasted from Websites, E-mails, PDFs etc. how do I make pasted text the same size as the text it's being pasted into? David Lee Word 6 08-16-2015 10:46 AM
Cleaning up Text Pasted from Websites, E-mails, PDFs etc. Pasted text becomes single long line qaz1 Word 1 07-25-2015 04:13 AM
Cleaning up Text Pasted from Websites, E-mails, PDFs etc. Pasted text comes in columns yotas312 Word 2 11-12-2011 07:58 AM
Trying to highlight pasted text in a macro goldengate Word VBA 0 09-14-2010 09:41 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 08:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft