Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 09-30-2017, 12:13 PM
poetofpiano poetofpiano is offline Why does this Macro take so long to execute? Windows 8 Why does this Macro take so long to execute? Office 2013
Novice
Why does this Macro take so long to execute?
 
Join Date: Sep 2015
Posts: 25
poetofpiano is on a distinguished road
Default Why does this Macro take so long to execute?

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!
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute autocorrects? KaiserD2 Word 6 04-03-2017 10:18 PM
Simple Hide columns macro, when I execute it hides everything left of selection, please help mcronin Excel Programming 2 08-31-2016 05:15 PM
Why does this Macro take so long to execute? I need to convert shaded text into highlighted text on about 80 different long documents. VBA macro? AustinBrister Word VBA 8 05-28-2015 02:42 PM
Why does this Macro take so long to execute? Find and Execute cksm4 Word VBA 1 10-22-2011 11:36 PM
Why does this Macro take so long to execute? How do I call/execute an Excel macro from Access 2003 KramerJ Excel 2 05-11-2009 11:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:44 PM.


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