Find Synonym for Selected Text using MS Word VBA

How do we refer Synonym for a word usually?

Find Synonym For Word
Dictionary – Find Synonym For Word

To view synonym of a text in MS Word,

  1. We have to place the cursor on the word, then
  2. Right click to get the popup menu and
  3. Select option “Synonym”.

Wouldn’t it be nice if we have a keyboard shortcut, to quickly refer the meaning for a word? And also learn bit of MS Word VBA code.

Wand and the Spell

 Let’s write a macro to display all possible synonyms for a word. Then assign it to a short cut key, so that anyone can use it easily.

To write a VBA code in MS word, press Alt + F11 to get to VB editor. Then copy paste the below code.

Sub Get_Synonym()

    '''''Define Variables
    Dim sText As String
    Dim sList As String
    
    '''''Assign selected Text to Variable
    sText = Selection.Text
    
    '''''Get All Synonym For the Selected Text
    For i = 1 To Application.SynonymInfo(sText).MeaningCount
        sList = sList & Application.SynonymInfo(sText).MeaningList(i) & ", "
    Next i
    
    '''''Display List of Sysnonyms to User
    sList = sList & Application.SynonymInfo(sText).MeaningCount
    MsgBox sList
    
End Sub

Do not run this code directly by pressing F5. We have to map this macro to a Keyboard shortcut, as explained below.

Assign Macro to Keyboard Shortcut

The explanation looks bit lengthier. But, you just have to browse through only few settings page to complete this process.

  1. Go to Menu File -> Word Options -> Customize -> Keyboard Shortcuts Customize.
  2. Popup for “Keyboard Customize” settings will be displayed.
  3. Select “Macro” from the Categories. It will display all macros in current workbook.
  4. Click on Macro “Get_Synonym” which we just copy pasted from this page.
  5. Click on Text box “Press New Shortcut key” and just press ‘Control key’ and ‘Q’. Textbox will automatically display Ctrl + Q.
  6. Click “Assign” and then Close the Window.
Customize Keyboard Shortcuts in Word
Customize Keyboard Shortcuts in Word

Read Also: How to Record Macro in Office Excel?

We have finished assigning the Macro to Keyboard shortcut Ctrl + Q. Now go to the word document.

Type any word (Example: Office). Select this word and then press Ctrl + Q. A Message box will appear with all synonyms available with MS Word.

Additional Reference: How to customize Keyboard Shortcut?

Leave a Reply