Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 11-24-2014, 08:41 AM
Sandhya Sandhya is offline Search the words of different document Windows 7 32bit Search the words of different document Office 2007
Novice
Search the words of different document
 
Join Date: Nov 2014
Posts: 21
Sandhya is on a distinguished road
Default Seach for the whole word

Dear All,

As below code i am able to search for the words existing in the table, but it is not checking as a whole in active document.

example: if i keep the abbrevations like "ar" means "as required" and "in" means inch, where as it is highlight all ar letters where ever it is finding,

from the word argument it is highlighting ar and in from instructions first two letters,

Kindly help me in this regard.


Quote:
Originally Posted by gmayor View Post
Create a document with a single column table. Put one of the phrases in each cell (no blanks) save the document then put the name and path in the following macro in place of "C:\Path\Table.docx". Run the macro on your document with the phrases.

Code:
Sub Highlighting()
Dim oChanges As Document, oDoc As Document
Dim oTable As Table
Dim oCell As Cell
Dim oRng As Range
Dim rFindText As Range
Const sFname As String = "C:\Path\Table.docx"
    Set oDoc = ActiveDocument
    Set oChanges = Documents.Open(Filename:=sFname, Visible:=False)
    Set oTable = oChanges.Tables(1)
    For Each oCell In oTable.Range.Cells
        If Len(oCell.Range) > 2 Then
            Set oRng = oDoc.Range
            Set rFindText = oCell.Range
            rFindText.End = rFindText.End - 1
            With oRng.Find
                .ClearFormatting
                .Replacement.ClearFormatting
                Do While .Execute(FindText:=rFindText, _
                                  MatchWholeWord:=True) = True
                    oRng.HighlightColorIndex = wdBrightGreen
                Loop
            End With
        End If
    Next oCell
lbl_Exit:
    oChanges.Close 0
    Set oChanges = Nothing
    Set oDoc = Nothing
    Set oRng = Nothing
    Set rFindText = Nothing
    Exit Sub
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search the words of different document Search for italicized words ep2002 Word 4 11-10-2014 10:23 PM
Macro to Search for all words with (R) and place in new document kd12 Word VBA 2 06-10-2014 02:25 PM
How to search for 2 words at the same time mrayncrental Word VBA 1 06-08-2014 03:08 AM
Multiple words, one search return2300 Word VBA 0 08-30-2013 12:26 PM
Search the words of different document Search for words starting in capitals surreytom Word VBA 3 04-01-2012 01:41 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:57 PM.


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