![]() |
|
#1
|
|||
|
|||
|
Hi, I am newcomer to this forum and need help.
Let's say I 'm going to write a text. Of course there will be repeated words. Since I write in Russian I need a macro that will highlight all the instances of cognate words on a page or in the text itself. To be correct I need only the roots of the word to be highlighted. Where a root is 4 to 6 characters (letters) long. Is it possible to write such a macro? |
|
#2
|
||||
|
||||
|
Have you tried using Find/Replace with the 'Find all word forms' option and setting the replacement to use highlighting? Do note, though, that this probably won't find verb:noun cognates.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Dear Paul, thank you for prompt reply.
Somewhere in the Internet I found the following macro. Code:
Sub HighlightRepeatedWords()
'
' HighlightRepeatedWords
'
Dim oRng As Word.Range
Dim arrWords
Dim i As Long
arrWords = Array("work", "dialogue", "would like", "first of all")
For i = 0 To UBound(arrWords)
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = arrWords(i)
.MatchWholeWord = False
.Replacement.Highlight = True
' .MatchCase = True
.Execute Replace:=wdReplaceAll
End With
Next
End Sub
I do not mind if all of the words needed are highlighted by one color. Could you suggest what to do in this case? |
|
#4
|
||||
|
||||
|
Quote:
arrWords = Array("work", "dialogue", "would like", "first of all", _ "lorem ipsum", "dolor", "amet sit") PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
Sorry again but VB says "Too many line continuations". I've got 34 lines with 196 words.
What can be wrong? |
|
#6
|
||||
|
||||
|
Try making your lines longer, so you use less continuations... I've just finished adding 300 more words to the array.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#7
|
|||
|
|||
|
Thank you Paul. Everything works fine now. One more question.
Let's say I have an A-4 (or A-5) size page and need to see repeated words on a single page, i.e. page by page. Is that possible? ![]() Is it also possible to highlight repeated words with different colours for different pages? |
|
#8
|
||||
|
||||
|
Yes, but that would require quite a different macro. Furthermore, given that page boundaries typically depend on whatever the active printer is, you could get different results just by changing printers.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#9
|
|||
|
|||
|
Paul, what kind of macro will be needed?
The problem is not with the printer but rather with page margins, line distance, font size, etc. How can it be done? |
|
#10
|
||||
|
||||
|
Quote:
A macro that processes each page separately requires significantly more code to iterate through the pages and limit the Find ranges to the 'current' page only. But doing that with a simple 'ReplaceAll' wouldn't achieve anything that doing the same for the whole document in one pass would do. From your last post, however, I gather you only want the words highlighted when they occur more than once on the same page. Managing that adds yet another layer of complication. Try the following: Code:
Sub FindDuplicatesByPage()
Application.ScreenUpdating = False
Dim i As Long, j As Long, k As Long, arrWords
Dim RngPg As Range, Rng As Range, Rng1 As Range
arrWords = Array("Lorem", "ipsum", "dolor", "amet")
With ActiveDocument
For i = 1 To .ComputeStatistics(wdStatisticPages)
For j = 0 To UBound(arrWords)
Set Rng = .GoTo(What:=wdGoToPage, Name:=i)
Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
Set RngPg = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
k = 0
With Rng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = arrWords(j)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = False
.Execute
End With
If .Find.Found Then Set Rng1 = .Duplicate
Do While .Find.Found
If .InRange(RngPg) Then
k = k + 1
If k > 1 Then .Duplicate.HighlightColorIndex = wdBrightGreen
Else
Exit Do
End If
.Collapse wdCollapseEnd
.Find.Execute
Loop
If k > 1 Then Rng1.HighlightColorIndex = wdBrightGreen
Set Rng1 = Nothing
End With
Next
Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Tags |
| highlight cognate words |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple identities in separate Outlook instances? | brucemc777 | Outlook | 3 | 07-08-2014 10:36 PM |
multiple instances available?
|
Guloluseus | Project | 3 | 01-31-2014 02:42 PM |
| Word 2010 running multiple instances | JBE | Word | 0 | 09-28-2012 06:00 PM |
Email Duplicates & Multiple Instances Running
|
trim | Outlook | 2 | 03-13-2012 11:25 AM |
| Text Highlighting in Yellow ??? | mark4man | Publisher | 0 | 12-15-2005 06:46 PM |