View Single Post
 
Old 05-16-2021, 01:43 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
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

Do you really need to be specific with the find highlight color? Isn't it constrained enough being in the comments, having the text "Andy:" and being highlighted?. Also you shouldn't need to loop through each comment if you search in the storyrange.
Code:
Sub FindReplace2() ' 05/14/2021
  Dim iFindColor As Integer, iReplaceColor As Integer, myComment As Comment
  
  'Application.ScreenUpdating = False
  
  ' (These variables are ordinarily set via input box
  ' 7 = yellow; 5 = pink; 4 = Bright Green; 3 = Turquoise (Bright Blue)):
  iFindColor = 5
  iReplaceColor = 4
                  
  'DoEvents ' For large docs, Word crashes without DoEvents
  Options.DefaultHighlightColorIndex = iReplaceColor
  With ActiveDocument.StoryRanges(wdCommentsStory).Find
    .ClearFormatting
    .Text = "Andy:"
    .Highlight = True
    .Replacement.Highlight = True
    .Forward = True
    .Execute Replace:=wdReplaceAll
  End With

  'Application.ScreenUpdating = True
  MsgBox "Done"
End Sub
If you still need to include the hilite color test then the macro drags a whole lot slower. This chunk looks cleaner than what you had but I don't know that it will be noticeably faster.
Code:
  With ActiveDocument.StoryRanges(wdCommentsStory).Find
    .ClearFormatting
    .Text = "Andy:"
    .Highlight = True
    .Replacement.Highlight = True
    .Forward = True
    .Execute
    Do While .Found = True
      If .Parent.HighlightColorIndex = iFindColor Then .Parent.HighlightColorIndex = iReplaceColor
      .Execute
    Loop
  End With
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Guessed; 05-16-2021 at 05:30 PM.
Reply With Quote