• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Replicate Smart Lookup using a macro

Slipstick Systems

› Developer › Replicate Smart Lookup using a macro

Last reviewed on October 9, 2018     8 Comments

I haven’t posted a Lazy Programmer’s macro in a long time but the opportunity to do some lazy programming arose this week when a user wanted to replace Bing in the Smart Lookup function with Google. While this is not possible, you can use a macro to (mostly) replicate the feature using your favorite search engine.

right click on a word or phrase and choose smart lookup

Outlook 2016's Smart Lookup feature is locked in to using Bing as the search engine. My question is would it be possible to write macro which adds an option to the context popup menu when text in an email is selected and right-clicked, that would allow us to search with Google - even if it meant calling out to an external browser?

Is it doable? Sure. We can send the selected word or phrase to your favorite search engine in your favorite browser. We’re not able to add to the right-click context menu or open the search in a side panel using a simple macro; you could do this using an addin, which is beyond the scope of the Lazy Programmer series.

With this macro, you select the word or phrase then click the button on the ribbon:
select the phrase and run the macro

The selected text is sent to the search engine:
search results

To put this together, we take code from two macros here at slipstick.com. We start with the macro at Create Task or Appointment and Insert Selected Text to create a variable from the selected text, while removing the code that creates the task. Then we send the search URL to a browser. Done.

Thanks to the GetCurrentItem function, this macro will work with selections in the reading pane, in an open message, or when composing a message. You'll need to customize the ribbon or Quick Access Toolbar in the main Outlook window, an open message, and in the compose form.

October 9 2018: Changed macro to use the default browser (and added a version to use in Word.)

If you are using 64-bit Office, the Private Declare Function ShellExecute macro will be in red - you need you use this as the first line, with PtrSafe between Declare Function:
Private Declare PtrSafe Function ShellExecute _

Private Declare Function ShellExecute _
  Lib "shell32.dll" Alias "ShellExecuteA" ( _
  ByVal hWnd As Long, _
  ByVal Operation As String, _
  ByVal Filename As String, _
  Optional ByVal Parameters As String, _
  Optional ByVal Directory As String, _
  Optional ByVal WindowStyle As Long = vbMinimizedFocus _
  ) As Long

Sub SearchGoogle()
' Set reference to Word object model
' in VBA Editor, Tools, References
    
Dim objMail As Object 'Outlook.MailItem
Dim objWord As Word.Application
Dim objInsp As Inspector
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim strPhrase As String
Dim oApp As Object
Dim lSuccess As Long
 
On Error Resume Next
    
Set objMail = GetCurrentItem()

' copy the selection to the clipboard
Set objInsp = objMail.GetInspector
    If objInsp.EditorType = olEditorWord Then
        Set objDoc = objInsp.WordEditor
        Set objWord = objDoc.Application
        Set objSel = objWord.Selection
         
        strPhrase = objSel
    End If

Dim strURL As String
' send to google search
strURL = "https://www.google.com/search?q=" & strPhrase

' start browser code block

lSuccess = ShellExecute(0, "Open", strURL)

' end browser code block

Set objMail = Nothing
Set objSel = Nothing
Set objInsp = Nothing
Set objWord = Nothing
End Sub
 
 Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
           
    Set objApp = Application
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
       
    Set objApp = Nothing
End Function

Customizations

You can change the search engine url to any search engine. Common search urls are in the table below.

Search EngineURL to use
Googlehttps://www.google.com/search?q=
DuckDuckGohttps://duckduckgo.com/?q=
Yahoohttps://search.yahoo.com/search?p=
Merriam-Webster dictionaryhttps://www.merriam-webster.com/dictionary/

If you want to open the link in a Google and it is NOT set as your default browser, you need to set the path to the browser and call it using Shell.

Use this to call Chrome. (Change the file path to use Firefox):

' start browser code block

Dim browserPath As String
browserPath = Chr(34) & "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & Chr(34)
' use double quotes around multiword phrases
Shell (browserPath & " -url " & Chr(34) & strURL & Chr(34))
DoEvents

' end browser code block

Use this to use Internet Explorer:

' start browser code block

Set oApp = CreateObject("InternetExplorer.Application")
' use CLng(2048) to open in a new tab in the current window
oApp.navigate strURL ', CLng(2048)

  oApp.Visible = True

'wait for page to load before passing the web URL
  Do While oApp.Busy
  DoEvents
  Loop
' end browser code block

 

Replicate Word's Smart Lookup

This version of the macro works in Word. Copy and paste the code into Word's VBA editor and create a button the ribbon (or assign a shortcut to the macro.)

To use it: Select the word or phrase and run the macro. This will open a tab in your default browser with the search criteria.

If you are using 64-bit Office, the Private Declare Function ShellExecute macro will be in red - you need you use this as the first line, with PtrSafe between Declare Function:
Private Declare PtrSafe Function ShellExecute _

Private Declare Function ShellExecute _
  Lib "shell32.dll" Alias "ShellExecuteA" ( _
  ByVal hWnd As Long, _
  ByVal Operation As String, _
  ByVal Filename As String, _
  Optional ByVal Parameters As String, _
  Optional ByVal Directory As String, _
  Optional ByVal WindowStyle As Long = vbMinimizedFocus _
  ) As Long

Sub SearchGoogleWord()
    Dim lSuccess As Long
    
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim strPhrase As String
Dim oApp As Object
 
On Error Resume Next
    
Set objWord = Word.Application
Set objSel = objWord.Selection
         
strPhrase = objSel
    
' send to google search
Dim strURL As String

strURL = "https://www.google.com/search?q=" & strPhrase
    
lSuccess = ShellExecute(0, "Open", strURL)

Set objSel = Nothing
Set objWord = Nothing
End Sub

How to use the macro on this page

First: You need to have macro security set to low during testing. The macros will not work otherwise.

To check your macro security in Outlook 2010 and newer, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007, look at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

Set a reference to Word Object Library
This macro uses the Word Object Library. If you receive a "User-defined type not defined" error, you didn't to set a reference to the Word object library.

  1. Go to Tools, References menu.
  2. Locate the object library in the list and add a check mark to it. (Word object library version number will match your Outlook's version number.)
    select the word object library

Add the macro to a button on the ribbon

  1. Open File, Options, Customize Ribbon
  2. Select Macros from the Choose commands from dropdown (1)
  3. Add a New Group to the ribbon (2)
  4. Select the Search macro (3)
  5. Click Add to add the macro to the new group. (4)
  6. Click Rename to give it a friendly name and an icon. (5)

If you prefer using the Quick Access Toolbar, add a macro button to it instead.
create a button for the macro

More information as well as screenshots are at How to use the VBA Editor

More Information

Create Task or Appointment and Insert Selected Text
Open All Hyperlinks in an Outlook Email Message

Replicate Smart Lookup using a macro was last modified: October 9th, 2018 by Diane Poremsky
Post Views: 2

Related Posts:

  • Open Hyperlinks in an Outlook Email Message
  • Replicate GTD: Create a task after sending a message
  • Save and Open an Attachment using VBA
  • Macro to Print Outlook email attachments as they arrive

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
8 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

bc@slipstick.com
September 5, 2020 1:45 pm

Thank you for this.

0
0
Reply
Peter Perros
April 30, 2020 11:14 pm

Diane,
The Word macro above works well with Mozilla, but not with latest versions of Edge or Chrome. With the latter 2 browsers only the first word of a string is passed to the browsers. I've reset Mozilla as the default browser. Just wondering if you might be able to replicate this on your system and offer comments?

15 mins later...
And of, course the moment I post it fixes itself...

0
0
Reply
Sammy
May 16, 2018 11:13 pm

Hi,

This seems to be working nicely! Thanks a lot.
Just one concern. When you haven't selected any word and simply click the ribbon button, why does it search for random letters? For example, I am in outlook, in ht inbox, some email is selected and without selecting any text, I just click Search Google(The name I gave to the ribbon button) for fun, and it searches Google for the letter W or sometimes A or T or any random letter. How can we prevent this from happening? I hope I was able to express my concern properly.

0
0
Reply
José Rodríguez Molina
February 6, 2018 2:04 pm

Thank you so much for posting this code. Me and people in my company have to use Outlook a lot. From Outlook they 1-(copy an items catalog number), 2-(open a new page), many other steps, until they finally get the result. With this I am helping them cut time by half or more!

So thank you so much! It has been very helpful.

0
0
Reply
Alan
October 21, 2017 1:25 am

I worked it out. Just needed double quotes round the search phrase strURL. Here's the amended Chrome browser code:

Dim browserPath As String
browserPath = Chr(34) & "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & Chr(34)

Shell (browserPath & " -url " & Chr(34) & strURL & Chr(34))
DoEvents

Sorry for all the messages.
Love your work!

1
0
Reply
Diane Poremsky
Author
Reply to  Alan
October 22, 2017 12:25 am

thanks for the information!

2
-1
Reply
Alan
October 21, 2017 1:18 am

Just found one snag with the macro. When using Chrome as the browser, then selecting a multiple word phrase and searching, it launches separate tabs in the browser for each word. The first word is searched for, but the following words in the other tabs go in without the search URL. Using IE it captures and searches for the whole phrase together in one go, as expected.

Any idea what I'd need to change to make Chrome behave the same as IE?

3
-3
Reply
Alan
October 21, 2017 1:06 am

Thanks Diane. Nice work, works a treat.

3
-2
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 3

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Reset the New Outlook Profile
  • Disable "Always ask before opening" Dialog
  • This operation has been cancelled due to restrictions
  • How to Hide or Delete Outlook's Default Folders
  • Adjusting Outlook's Zoom Setting in Email
  • Mail Templates in Outlook for Windows (and Web)
  • Removing Suggested Accounts in New Outlook
  • Remove a password from an Outlook *.pst File
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment