I execute the following Macro after manually selecting a block of text that has been pasted into Word from a PDF to replace all the line breaks with spaces and thus make it a single, normal paragraph:
Code:
Sub LinkLinesOfPDF_Text()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = vbCr
.Replacement.Text = " "
.Forward = False '!!!
.Wrap = wdFindStop '!!!
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute , , , , , , , , , , wdReplaceAll
' remove double spaces:
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " "
.Replacement.Text = " "
.Forward = False
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
It works fine, but I have strangely found that at least in Word docs that have a lot of text, the action will take 3 to 4 seconds to complete even though I am only selecting a few lines of text. I do not notice this problem when I have a brand new word document with little text on which I am performing the action.
Is this delay unavoidable, or is there a more elegant, efficient way for me to replace all new lines with spaces in a given selection of text?
Thank you so much in advance!