Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-21-2019, 03:30 PM
macropod's Avatar
macropod macropod is offline check for duplicates of a word within next 100 words Windows 7 64bit check for duplicates of a word within next 100 words Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To limit operations to a Selection:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim RngTxt As Range, RngFnd As Range, RngTmp As Range, RngSel As Range
Dim StrTmp As String, StrTxt As String
Dim i As Long, j As Long, k As Long
Const StrExcl As String = "|a|an|and|from|in|is|of|the|to|with|": j = 100
Set RngSel = Selection.Range
With ActiveDocument
  For i = .Range(0, Selection.Start + 1).Words.Count To .Range(0, Selection.End).Words.Count - 1
    If InStr(StrExcl, "|" & LCase(Trim(.Words(i))) & "|") = 0 Then
      If .Words(i).InlineShapes.Count = 0 Then
        If .Words(i).Fields.Count = 0 Then
          StrTxt = .Words(i).Characters.First
          If ((Asc(StrTxt) > 64) And (Asc(StrTxt) < 91)) Or ((Asc(StrTxt) > 96) And (Asc(StrTxt) < 123)) Then
            StrTxt = Replace(Trim(.Words(i)), vbCr, "")
            Set RngTxt = .Range(.Words(i).Start, .Range.End)
            With RngTxt
              If .Words.Count > j Then .MoveEnd Unit:=wdWord, Count:=-(.Words.Count - j)
            End With
            Set RngFnd = .Range(.Words(i).End, RngTxt.End)
            With .Range(.Words(i).End, RngTxt.End)
              With .Find
                .ClearFormatting
                .Replacement.ClearFormatting
                .Text = StrTxt
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindStop
                .Format = False
                .MatchCase = False
                .MatchWholeWord = True
                .MatchWildcards = False
                .MatchAllWordForms = True
                On Error Resume Next
                .Execute
                On Error GoTo 0
              End With
              If .Find.Found = True Then
              If .InRange(RngSel) = False Then Exit For
                Set RngTmp = RngTxt.Words.First
                RngTmp.MoveEndWhile " ", -1
                RngTmp.HighlightColorIndex = wdBrightGreen
                Set RngTmp = .Words.Last
                RngTmp.MoveEndWhile " ", -1
                RngTmp.HighlightColorIndex = wdBrightGreen
              End If
            End With
          End If
        Else
          i = i + .Words(i).Fields(1).Result.Words.Count - 1
        End If
      End If
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub

__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 01-22-2019, 04:24 PM
sylvio sylvio is offline check for duplicates of a word within next 100 words Windows 7 64bit check for duplicates of a word within next 100 words Office 2010 32bit
Novice
check for duplicates of a word within next 100 words
 
Join Date: Jan 2017
Posts: 20
sylvio is on a distinguished road
Default

Dear macropod,

thank you very much for your patience and help.
I guess now the macros works as it should.

Just the last wish, which can be ignored without any problem actually.
It would be helpful to see the same highlight color of similar/duplicated words.
No idea how difficult to realize this, if too much, let's stop now
Because I understand that a random coloration of, let's say, three words will lead to the same highlight color of only two last words, the first will be colored by another color.
The macros should somehow check every word whether it has already a highlight, if not and if there is a duplicate then apply random highlight to the word and its duplicate, if yes apply the same color to the duplicate...
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
check for duplicates of a word within next 100 words Macro to check against Columns & Delete Duplicates cjamps Excel Programming 27 12-18-2017 06:38 AM
check for duplicates of a word within next 100 words how to check for duplicated words / cells ? iSlam Khaled Word Tables 11 05-05-2015 08:07 PM
check for duplicates of a word within next 100 words Adding words to spell check dictionary oakwoodbank Word 17 02-27-2015 08:09 PM
check for duplicates of a word within next 100 words Spell check adding words riweir Word 3 11-30-2011 09:03 PM
Edit spell check dic to exclude words? franklekens Word 1 07-03-2010 09:57 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:52 AM.


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