Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-14-2022, 01:14 AM
stky stky is offline Highlight not working for me Help Windows 10 Highlight not working for me Help Office 2013
Advanced Beginner
Highlight not working for me Help
 
Join Date: Apr 2021
Posts: 30
stky is on a distinguished road
Default Highlight not working for me Help

Sub NonBreakSpace()
Application.ScreenUpdating = False

Options.DefaultHighlightColorIndex = wdTurquoise
Selection.Find.Replacement.Highlight = True

Dim StrFR As String, i As Long
StrFR = "[<(et)> <(al)>]|\1^s\2"

With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchAllWordForms = False


.MatchSoundsLike = False
.MatchWildcards = True
.Replacement.Highlight = wdTurquoise

For i = 0 To UBound(Split(StrFR, "|")) Step 2
.text = Split(StrFR, "|")(i)
.Replacement.text = Split(StrFR, "|")(i + 1)
.Execute Replace:=wdReplaceAll
Next
End With

Application.ScreenUpdating = True
End Sub
Reply With Quote
  #2  
Old 01-14-2022, 03:43 AM
gmayor's Avatar
gmayor gmayor is offline Highlight not working for me Help Windows 10 Highlight not working for me Help Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You don't need the loop
Code:
Sub NonBreakSpace()
Const strFR As String = "<(et)> <(al)>|\1^s\2"
Dim i As Long
    Options.DefaultHighlightColorIndex = wdTurquoise
    With ActiveDocument.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Highlight = True
        .Text = strFR
        .Forward = True
        .Wrap = wdFindStop
        .MatchWildcards = True
        .Text = Split(strFR, "|")(0)
        .Replacement.Text = Split(strFR, "|")(1)
        .Execute Replace:=wdReplaceAll
    End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to highlight specific weeks in the Gantt Chart view but they should be working hours PL@plan Project 1 05-05-2021 12:23 PM
highlight bar freeriding Project 0 12-07-2018 05:25 AM
Tasks Switch to Non-Working Days on Working Calendar danelloc Project 3 10-02-2017 12:38 PM
Highlight not working for me Help Ugghhh....Highlight Text not working mrayncrental Word VBA 1 02-10-2014 10:58 PM
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 11:33 PM.


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