+ Reply to Thread
Results 1 to 3 of 3

Macro to highlight keywords-Macrobutton not working fine

  1. #1
    Registered User
    Join Date
    01-07-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    9

    Macro to highlight keywords-Macrobutton not working fine

    Hi All,

    I am facing issues with the word macro that I have created. I have created a macro to change the font and formatting of specific words mentioned in the inputbox. I am facing two issues:
    1. The macro works well when I use Alt +F8. However whenever I am adding a macro button it doesnt seem to highlight the input text.
    2. Can we add multiple words in the input box (seperated by a space) and all get highlighted at once, instead of running the macro again for different set of words again and again.

    I have used the following code:
    Sub Wordhighlighter()
    '
    ' Highlights words of specific interest to you'

    MyInput = inputbox("Please enter the words which you want to highlight")
    Selection.Find.ClearFormatting
    With Selection.Find
    .Text = MyInput
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = False
    With Selection.Find.Replacement.Font
    .Italic = True
    .Color = wdColorRed
    .Bold = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,835

    Re: Macro to highlight keywords-Macrobutton not working fine

    Hi ,

    The code you posted is not capable of highlighting anything, regardless of whether you use a MACROBUTTON. Also, docx files can't be saved with macros. Based on what you posted, the following should do what you want - in a docm file.
    Please Login or Register  to view this content.
    PS: When posting code, please use the code tags. They're on the menu.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    01-07-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Macro to highlight keywords-Macrobutton not working fine

    Thanks you so much! It worked perfectly fine...
    I am new to VBA, and mainly tried this code based on macro-recorder, but I am glad that the this code solved my issue!

    Thanks again! :D

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1