VBA How to Exclude Words from Macro

VorLag

Board Regular
Joined
May 13, 2013
Messages
205
This macro is actually in Word, but the functions shouldn't be too different. What I want to do is to highlight all words ending in -ing but excluding some words like bing (as in the cherry), thing, and being. I figured out how to get the macro to skip over 3 and 4 letter words, but I am not sure how to tweak this to also skip 5 letter words.

I would prefer to have a word list that the macro excludes.

How do you do that? Here is the macro so far:


Code:
Sub HighlightING()

Application.ScreenUpdating = False
Dim HlLt As Long
HlLt = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdYellow
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = "<[!^09-^13 ][!^09-^13 ]@ing>"
  .Replacement.Highlight = True
  .Replacement.Text = "^&"
  .Forward = True
  .Wrap = wdFindStop
  .Format = True
  .MatchWildcards = True
  .Execute Replace:=wdReplaceAll
End With
Options.DefaultHighlightColorIndex = HlLt
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,216,075
Messages
6,128,665
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top