View Single Post
 
Old 01-20-2021, 09:25 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 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