Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 02-02-2022, 03:30 PM
Guessed's Avatar
Guessed Guessed is offline highlight text in array Windows 10 highlight text in array Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
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

I think you put the wholeword line in the wrong place. Try this variation on Graham's code
Code:
Sub PrintSpecificWordsII()
  Dim myWords() As String
  Dim lngIndex As Long
  Dim oStory As Range
  myWords = Split("Word1|Word2|Word3|Word4|Word5", "|")
  For lngIndex = LBound(myWords) To UBound(myWords)
      For Each oStory In ActiveDocument.StoryRanges
          With oStory.Find
              .ClearFormatting
              .Text = myWords(lngIndex)
              .Forward = True
              .MatchWholeWord = True
              While .Execute
                  oStory.HighlightColorIndex = wdBrightGreen
                  oStory.Select
                  Application.PrintOut Range:=wdPrintCurrentPage
                  oStory.Collapse wdCollapseEnd
              Wend
          End With
          If oStory.StoryType <> wdMainTextStory Then
              While Not (oStory.NextStoryRange Is Nothing)
                  Set oStory = oStory.NextStoryRange
                  With oStory.Find
                      .ClearFormatting
                      .Text = myWords(lngIndex)
                      .Forward = True
                      .MatchWholeWord = True
                      While .Execute
                          oStory.HighlightColorIndex = wdBrightGreen
                          oStory.Select
                          Application.PrintOut Range:=wdPrintCurrentPage
                          oStory.Collapse wdCollapseEnd
                      Wend
                  End With
              Wend
          End If
      Next oStory
  Next lngIndex
lbl_Exit:
  Set oStory = Nothing
  Exit Sub
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
like to highlight web text, enter cntl key, have text appended to same onenote pate bobk544 OneNote 0 12-10-2017 11:49 AM
highlight text in array Create an array or list of highlighted text in selection rjrichar40 Word VBA 1 09-03-2014 01:02 PM
highlight text in array Convert String Array to Integer Array from a User Input? tinfanide Excel Programming 4 12-26-2012 08:56 PM
highlight text in array Array into ComboBox + Macro-Text into ActiveDocument Vivi Word VBA 1 01-27-2010 07:03 AM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:54 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