Removing hyphens

T

Tim

I have a document that was scanned and OCR ran on it and it has been
converted to a .txt file. I am trying to do two things:
1. Remove all the hyphens at the end of the line. It appears that there
is a hyphen, space, and a carriage return. Is there a way to make this
do the whole document.
2. remove the carriage returns at the end of each line of a paragraph.
My macro to do this now goes like:
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.TypeBackspace
This works one line at a time, but maybe there is a better way of doing
this.

This is Word2004 11.1 using Mac 10.4.2.
 
E

Elliott Roper

Tim said:
I have a document that was scanned and OCR ran on it and it has been
converted to a .txt file. I am trying to do two things:
1. Remove all the hyphens at the end of the line. It appears that there
is a hyphen, space, and a carriage return. Is there a way to make this
do the whole document.
2. remove the carriage returns at the end of each line of a paragraph.
My macro to do this now goes like:
Selection.MoveDown Unit:=wdParagraph, Count:=1
Selection.TypeBackspace
This works one line at a time, but maybe there is a better way of doing
this.

This is Word2004 11.1 using Mac 10.4.2.

1. Creative use of find and replace?
find "- ^p" replace "" without the "s of course

If OCR gives you two consecutive para marks at the real end of a
paragraph, try three passes through find and replace

A. find ^p^p replace /\ or something else not in the doc.
B. find ^p replace " " without the "s of course
C. find /\ replace with ^p

This might mangle formatting, but then OCR that preserves formatting is
mostly an accident.

You could of course put all this in a macro. I have one to do one
selection at a time, since the risk of mashing tables and lists is
pretty high.

you are welcome to this one:

Sub One_Paragraph()

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFind
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = " ^w"
.Replacement.Text = " "

You will note that it collapses multiple spaces to a single space in
the last three lines. That gets rid of doubled-up spaces where lines
ended in space para before you start.

Select the text you want to make into a single para and run the macro
(a keyboard shortcut for it is useful)
 
E

Elliott Roper

Oh bugger, for the second time today I have carelessly pasted stuff
into a post on this group. I do apologise.
There is more to this of course.
Sub One_Paragraph()

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFind
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = " ^w"
.Replacement.Text = " "

In full it is:

Sub One_Paragraph()

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFind
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = " ^w"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFind
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

sorry.
E
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top