Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-16-2019, 08:21 PM
Guessed's Avatar
Guessed Guessed is offline check for duplicates of a word within next 100 words Windows 10 check for duplicates of a word within next 100 words Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

Yes, it is possible but not particularly quick. There may be more efficient ways of doing it but my attempt at it resulted in the following code. Note there wasn't any comprehensive error checking done on this.
Code:
Sub DupWordMarks()
  Dim aWord As String, iCounter As Long, iWords As Long, iLen As Long, iTotalWords As Long
  Dim aRng As Range, iEnd As Long, i As Long
    
  iLen = 20   'the size of the range searched forward
  iTotalWords = ActiveDocument.Words.Count
  
  For iCounter = 1 To iTotalWords - 1
    Select Case Trim(ActiveDocument.Words(iCounter))
      Case "you", "a", "the", "can", "for", ".", "to", "and", ",", ";"
        'do nothing
      Case Else
        If iCounter + iLen < iTotalWords Then
          iEnd = iCounter + iLen
        Else
          iEnd = iTotalWords
        End If
        Set aRng = ActiveDocument.Range(ActiveDocument.Words(iCounter).End, ActiveDocument.Words(iEnd).End)
        For i = 1 To aRng.Words.Count
          If LCase(Trim(ActiveDocument.Words(iCounter))) = LCase(Trim(aRng.Words(i))) Then
            aRng.Words(i).HighlightColorIndex = wdPink
            Exit For
          End If
        Next i
    End Select
    'If iCounter = 500 Then Exit Sub   'enable an artificial restraint to stop the code when testing
  Next iCounter
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 



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