Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2012, 04:10 PM
markg2 markg2 is offline How to release hard returns? Windows 7 How to release hard returns? Office 2007
Expert
How to release hard returns?
 
Join Date: Nov 2009
Location: Evergreen, CO
Posts: 344
markg2 is on a distinguished road
Default How to release hard returns?


Office '07

I scanned a magazine page with OCR. The result of the OCR was displayed by a text reader. I cut and pasted the text into Word. The resultant text maintains the narrow column style of the magazine. I selected the entire text in Word hoping I could find a command that would release all the hard returns and allow the text to take the default Word right margin vs manually deleting the returns. No luck. Is there a way to do what I want?

Mark

I found the solution after a Google search: "MS Word allows the "carat p" symbol ^p (carat is the <shift> 6 key) to represent a carriage return in an MS-Word replace command."

Last edited by markg2; 04-22-2012 at 04:51 PM. Reason: Found solution
Reply With Quote
  #2  
Old 04-22-2012, 05:22 PM
Charles Kenyon Charles Kenyon is offline How to release hard returns? Windows Vista How to release hard returns? Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Try AutoCorrect.
Reply With Quote
  #3  
Old 04-22-2012, 06:33 PM
markg2 markg2 is offline How to release hard returns? Windows 7 How to release hard returns? Office 2007
Expert
How to release hard returns?
 
Join Date: Nov 2009
Location: Evergreen, CO
Posts: 344
markg2 is on a distinguished road
Default

I took a look and do not see any benefit. There is no hard return character option under find so it seems you'd have to enter the ^p in the find in any event.
Reply With Quote
  #4  
Old 04-22-2012, 08:29 PM
Charles Kenyon Charles Kenyon is offline How to release hard returns? Windows Vista How to release hard returns? Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Sorry, I meant Autoformat. See http://wordfaqs.mvps.org/CleanWebText.htm
Reply With Quote
  #5  
Old 04-22-2012, 08:39 PM
macropod's Avatar
macropod macropod is offline How to release hard returns? Windows 7 64bit How to release hard returns? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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 PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
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]
Reply With Quote
  #6  
Old 04-23-2012, 05:59 AM
markg2 markg2 is offline How to release hard returns? Windows 7 How to release hard returns? Office 2007
Expert
How to release hard returns?
 
Join Date: Nov 2009
Location: Evergreen, CO
Posts: 344
markg2 is on a distinguished road
Default

Thanks Paul,

The script description looks like what the doc ordered +. Would you mind pointing me in the direction of a link explaining how to install and invoke the script? If you remember, you had to do the same with the Excel script you provided a few years ago for my default workbook that's still in use with my every new spreadsheet :-).

Mark

Last edited by markg2; 04-23-2012 at 05:59 AM. Reason: Forgot salutation
Reply With Quote
  #7  
Old 04-23-2012, 06:11 AM
macropod's Avatar
macropod macropod is offline How to release hard returns? Windows 7 64bit How to release hard returns? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Mark,

That advice is included in post #6 itself
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 04-24-2023, 08:21 AM
Dr. Rick Dr. Rick is offline How to release hard returns? Windows 10 How to release hard returns? Office 2010
Novice
 
Join Date: Apr 2023
Location: Coastal N.C.
Posts: 4
Dr. Rick is on a distinguished road
Default

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
Reply With Quote
  #9  
Old 05-02-2023, 07:44 AM
Dr. Rick Dr. Rick is offline How to release hard returns? Windows 10 How to release hard returns? Office 2010
Novice
 
Join Date: Apr 2023
Location: Coastal N.C.
Posts: 4
Dr. Rick is on a distinguished road
Default

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.
Reply With Quote
  #10  
Old 05-02-2023, 06:19 PM
Guessed's Avatar
Guessed Guessed is offline How to release hard returns? Windows 10 How to release hard returns? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The name of the macro is irrelevant to the code BUT changing to Selection is problematic if you are also using .Wrap = wdFindStop

If the first replace found something at the end of the selection, what do you expect the second replace to find?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #11  
Old 05-04-2023, 08:23 AM
Dr. Rick Dr. Rick is offline How to release hard returns? Windows 10 How to release hard returns? Office 2010
Novice
 
Join Date: Apr 2023
Location: Coastal N.C.
Posts: 4
Dr. Rick is on a distinguished road
Default

Andrew Lockton
I'm new to the forum and feel over my head. Are you saying that if ".Wrap = wdFindStop" is in the code I was using (which it IS) that using Selection instead of ActiveDocument will cause a problem? It doesn't seem to; i.e., it seems to work perfectly when I go back to using CleanUpPastedText as the name and Selection in place of ActiveDocument.


Your question starting with "If the first replace found..." doesn't make much sense to me, but probably because I really don't understand every line of Macropod's code from #5 above.

Last edited by Dr. Rick; 05-04-2023 at 08:25 AM. Reason: clarity
Reply With Quote
  #12  
Old 05-04-2023, 10:58 AM
Charles Kenyon Charles Kenyon is offline How to release hard returns? Windows 11 How to release hard returns? Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by Dr. Rick View Post
***I really don't understand every line of Macropod's code from #5 above.
All of the lines with brackets [] in them are using Wild Cards, which are somewhat esoteric.
Reply With Quote
  #13  
Old 05-08-2023, 01:26 PM
Dr. Rick Dr. Rick is offline How to release hard returns? Windows 10 How to release hard returns? Office 2010
Novice
 
Join Date: Apr 2023
Location: Coastal N.C.
Posts: 4
Dr. Rick is on a distinguished road
Default

Thanks, Charles, you've given me a lot to study. I can tell I need to start at the beginning with VBA. I'm a very good (read "serviceable") BASIC programmer, and I used to compile a lot of BASIC programs with quickbasic; even dabbled in machine code for early Commodore machines. I get the general process of coding but the intricacies of ?Visual Basic (or whatever VBA might be) seem beyond me at present. One of the things I read on-line recommended constructing a macro with "record" (I've done maybe a hundred of these) and then dissect it by going into "edit" mode. Do you think this is a reasonable strategy? I just want to become more facile with macro writing, not looking to write groundbreaking software.
Anyway, thanks for responding.

Last edited by Dr. Rick; 05-08-2023 at 01:27 PM. Reason: clarify
Reply With Quote
  #14  
Old 05-08-2023, 01:38 PM
Charles Kenyon Charles Kenyon is offline How to release hard returns? Windows 11 How to release hard returns? Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,082
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Starting with recorded macros is fine. Note, though that the recorder does not write well-structured or efficient code. It also can't record some actions.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to release hard returns? 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
How to release hard returns? 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:04 PM.


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