Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 22,467
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
 

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 10:21 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