View Single Post
 
Old 09-30-2017, 07:34 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
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 delay may be due to some minor things in your code but may also be related to the format of what you have selected. I've done a tidy up on your code but it essentially does the same thing with less lines so may not be any quicker. I have a feeling that searching forward is faster than searching backwards but I could be wrong.
Code:
Sub MergeParagraph_Text()
  With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^p"  'same as vbCr but used by the find/replace dialog
    .Replacement.Text = " "
    .Forward = True   'search forwards instead of backwards
    .Wrap = wdFindStop  'stops replacing without asking if you want to do rest of doc
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    ' remove double spaces:
    .Text = "  "
    .Replacement.Text = " "
    .Execute Replace:=wdReplaceAll
  End With
End Sub
Ultimately, the code speed depends on what you have selected. If the selection includes table cells then there could be differences with the ^p and vbCr values and the code could stumble around a bit.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote