Consulting

Results 1 to 3 of 3

Thread: Finding and highlighting text in a word document

  1. #1
    VBAX Regular
    Joined
    Feb 2015
    Posts
    80
    Location

    Finding and highlighting text in a word document

    I have a userform (created through excel) that has 2 option buttons

    1 option is to have the prog look for the text "New Install", in a Word doc, highlight it, then print

    The other option is to look for "Install", highlight then print.

    The problem I am having is, when "Install" is selected, "Install" and the install part of "New Install" are both highlighted when printed.

    I have no problem opening or printing the document, just the highlighting part.

    There is probably a simple fix for this that is beyond my reach.

    Please, any help you can provide would be greatly appreciated. Thanks in advance.


    Chunk


    Here is the code that I am working with:

    If optbut_Install = True Then 
        wrdApp.Selection.Find.ClearFormatting 
        wrdApp.Selection.Find.Replacement.ClearFormatting 
        wrdApp.Selection.Find.Replacement.Highlight = True 
        With wrdApp.Selection.Find 
            .Text = "Install" 
            .Replacement.Text = "Install" 
            .Forward = True 
            .Wrap = wdFindContinue 
            .Format = True 
            .MatchCase = False 
            .MatchWholeWord = True 
            .MatchWildcards = False 
            .MatchSoundsLike = False 
            .MatchAllWordForms = False 
        End With 
        wrdApp.Selection.Find.Execute Replace:=wdReplaceAll 
        wrdApp.Options.DefaultHighlightColorIndex = wdYellow 
        wrdApp.Selection.Range.HighlightColorIndex = wdYellow 
    End If 
     
    If optbut_Newinstall = True Then 
        wrdApp.Selection.Find.ClearFormatting 
        wrdApp.Selection.Find.Replacement.ClearFormatting 
        wrdApp.Selection.Find.Replacement.Highlight = True 
        With wrdApp.Selection.Find 
            .Text = "New Install" 
            .Replacement.Text = "New Install" 
            .Forward = True 
            .Wrap = wdFindContinue 
            .Format = True 
            .MatchCase = False 
            .MatchWholeWord = True 
            .MatchWildcards = False 
            .MatchSoundsLike = False 
            .MatchAllWordForms = False 
        End With 
        wrdApp.Selection.Find.Execute Replace:=wdReplaceAll 
        wrdApp.Options.DefaultHighlightColorIndex = wdYellow
    Thread 53588 is the same. After I posted it I came to the realization it fits better here. Sorry for any inconvenience.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    A quick and dirty method is to first change "New Install" to something like "New Gobbledygook" process your Install words the change Gobbledygook back to Install.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular
    Joined
    Feb 2015
    Posts
    80
    Location
    gmaxey's reply is what I ended up using as a solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •