Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-06-2014, 09:56 AM
gekser gekser is offline Highlighting multiple word instances in text Windows 7 64bit Highlighting multiple word instances in text Office 2013
Novice
Highlighting multiple word instances in text
 
Join Date: Jul 2014
Posts: 5
gekser is on a distinguished road
Thumbs up Highlighting multiple word instances in text


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?
Reply With Quote
  #2  
Old 07-06-2014, 06:39 PM
macropod's Avatar
macropod macropod is offline Highlighting multiple word instances in text Windows 7 32bit Highlighting multiple word instances in text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Reply With Quote
  #3  
Old 07-09-2014, 11:28 PM
gekser gekser is offline Highlighting multiple word instances in text Windows 7 64bit Highlighting multiple word instances in text Office 2013
Novice
Highlighting multiple word instances in text
 
Join Date: Jul 2014
Posts: 5
gekser is on a distinguished road
Default What about that macro

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
It was yours but with a different name. My task is to use not just 4 (four) words as an array but 160. VB does not allow me to use so many words in a single string.

I do not mind if all of the words needed are highlighted by one color.

Could you suggest what to do in this case?
Reply With Quote
  #4  
Old 07-10-2014, 12:04 AM
macropod's Avatar
macropod macropod is offline Highlighting multiple word instances in text Windows 7 32bit Highlighting multiple word instances in text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by gekser View Post
My task is to use not just 4 (four) words as an array but 160. VB does not allow me to use so many words in a single string.
Your array can have vastly more than 160 words. The problem you might encounter is the VBE's line length limit. To deal with that, simply use line separators. For example:
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]
Reply With Quote
  #5  
Old 07-10-2014, 12:22 AM
gekser gekser is offline Highlighting multiple word instances in text Windows 7 64bit Highlighting multiple word instances in text Office 2013
Novice
Highlighting multiple word instances in text
 
Join Date: Jul 2014
Posts: 5
gekser is on a distinguished road
Default Line continuations

Sorry again but VB says "Too many line continuations". I've got 34 lines with 196 words.

What can be wrong?
Reply With Quote
  #6  
Old 07-10-2014, 01:01 AM
macropod's Avatar
macropod macropod is offline Highlighting multiple word instances in text Windows 7 32bit Highlighting multiple word instances in text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Reply With Quote
  #7  
Old 07-10-2014, 01:10 AM
gekser gekser is offline Highlighting multiple word instances in text Windows 7 64bit Highlighting multiple word instances in text Office 2013
Novice
Highlighting multiple word instances in text
 
Join Date: Jul 2014
Posts: 5
gekser is on a distinguished road
Default Highlighting multiple word instances in text

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?
Reply With Quote
  #8  
Old 07-10-2014, 01:13 AM
macropod's Avatar
macropod macropod is offline Highlighting multiple word instances in text Windows 7 32bit Highlighting multiple word instances in text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

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]
Reply With Quote
  #9  
Old 07-10-2014, 01:25 AM
gekser gekser is offline Highlighting multiple word instances in text Windows 7 64bit Highlighting multiple word instances in text Office 2013
Novice
Highlighting multiple word instances in text
 
Join Date: Jul 2014
Posts: 5
gekser is on a distinguished road
Default What kind of macro?

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?
Reply With Quote
  #10  
Old 07-10-2014, 05:46 AM
macropod's Avatar
macropod macropod is offline Highlighting multiple word instances in text Windows 7 32bit Highlighting multiple word instances in text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by gekser View Post
The problem is not with the printer but rather with page margins, line distance, font size, etc.
Changing the printer (or even just the driver) is enough on its own to affect Word's pagination. This is a well-documented fact.

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]
Reply With Quote
Reply

Tags
highlight cognate words

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple identities in separate Outlook instances? brucemc777 Outlook 3 07-08-2014 10:36 PM
Highlighting multiple word instances in text 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
Highlighting multiple word instances in text 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

Other Forums: Access Forums

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


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft