Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-20-2021, 09:25 PM
Guessed's Avatar
Guessed Guessed is offline speed up macro to Highlight Phrases in document based on list input from text file Windows 10 speed up macro to Highlight Phrases in document based on list input from text file Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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 two phrase macros could be simplified since they are reading the same source file. This would speed up your execution time by a considerable amount.

Then you can also reduce the total amount of code by making the macro into a function (or sub) with inputs. Note that this reduces the amount of code you have to maintain but won't be faster to execute.
Code:
Sub QC_Time()
  HighlightPhrases MyAcroFileName:="C:\Users\gontch\Desktop\Phrase Running List.txt", bAll:=True
  HighlightPhrases MyAcroFileName:="C:\Users\gontch\Desktop\Acronyms Running List.txt", bAll:=False
End Sub

Function HighlightPhrases(MyAcroFileName As String, bAll As Boolean)
  Dim MyString As String, rng As Range

  Application.ScreenUpdating = False
    Open MyAcroFileName For Input As #1
      Do While Not EOF(1)                 'loop through the file until the end of file marker is reached
        Line Input #1, MyString           'read line of text, place it in the MyString variable
        Set rng = ActiveDocument.Range    'Reset the Range object to the entire current document
        With rng.Find
          .Text = MyString
          .Replacement.Text = MyString
          .MatchCase = False
          .MatchWholeWord = True
          .Forward = True
          .Replacement.Highlight = True
          If bAll Then
            Options.DefaultHighlightColorIndex = wdPink
            .Execute Replace:=wdReplaceAll
          End If
          Options.DefaultHighlightColorIndex = wdYellow
          .Execute Replace:=wdReplaceOne
         End With
      Loop
    Close #1          'close the text file
  Application.ScreenUpdating = True
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Tags
acronym, highlight, replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
speed up macro to Highlight Phrases in document based on list input from text file Speed up macro that calls Excel-based function Peterson Word VBA 2 08-11-2020 06:18 AM
speed up macro to Highlight Phrases in document based on list input from text file Macro To Identify & Highlight Words In MS Word Based Upon A List In Excel File Column abhimanyu Word VBA 5 03-20-2020 01:33 PM
Macro to highlight duplicate phrases in document? taw Word VBA 0 02-27-2018 01:47 PM
speed up macro to Highlight Phrases in document based on list input from text file Inserting text from one word file into another based on an excel input jmaxcy Excel 14 11-01-2013 04:07 PM
Inserting text from one word file into another based on an excel input jmaxcy Word 3 11-01-2013 01:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:42 AM.


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