![]() |
#4
|
||||
|
||||
![]()
Try:
Code:
Sub Demo() Application.ScreenUpdating = False Dim i As Long, j As Long, k As Long, l As Long, x As Long, y As Long Dim Rng As Range, StrFnd As String With ActiveDocument StrFnd = InputBox("Please input the string to find.") x = InputBox("Please input the allowable string frequency.") y = InputBox("Please input the test paragraph interval.") For i = 1 To .Paragraphs.Count - 1 k = 0: l = 0 For j = i To .Paragraphs.Count Set Rng = .Range(.Paragraphs(i).Range.Start, .Paragraphs(j).Range.End) If Trim(.Paragraphs(j).Range.Text) <> vbCr Then k = k + 1 If k = y Then With Rng.Duplicate With .Find .ClearFormatting .Replacement.ClearFormatting .Format = False .Forward = True .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Text = StrFnd .Replacement.Text = "" .Wrap = wdFindStop .Execute End With Do While .Find.Found If .InRange(Rng) Then l = l + 1 .Collapse wdCollapseEnd .Find.Execute Else Exit Do End If Loop End With If l > x Then With Rng.Find .ClearFormatting .Replacement.ClearFormatting .Format = True .Forward = True .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Replacement.Highlight = True .Text = StrFnd .Replacement.Text = "^&" .Wrap = wdFindStop .Execute Replace:=wdReplaceAll End With End If End If Next Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
bakerkr | Word VBA | 4 | 10-19-2017 02:23 PM |
![]() |
zdodson | Word VBA | 1 | 07-11-2013 04:53 PM |
![]() |
bertietheblue | Word VBA | 9 | 07-01-2013 12:39 PM |
![]() |
redhin | Word VBA | 5 | 03-05-2013 05:42 AM |
![]() |
RBLampert | Word VBA | 13 | 10-23-2012 04:45 PM |