Add-in: Command Button in the Excel Right Click Pop-up Toolbar

m3ntos

New Member
Joined
Feb 26, 2011
Messages
1
Hi all!
I'm trying to create an add-in for Excel which adds a command button in the Excel right click toolbar. When I click on that button it should open an internet explorer window with a google search based on the value of active cell.
Your help is welcome!

class module (class1):
Code:
Public WithEvents appevent As Application
Private Sub appevent_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim cBut As CommandBarButton
    On Error Resume Next
        With Application
            .CommandBars("Cell").Controls("Google Search").Delete
            Set cBut = .CommandBars("Cell").Controls.Add(Temporary:=False)
        End With
                
        With cBut
           .Caption = "Google Search"
           .Style = msoButtonCaption
           .OnAction = SearchGoogleIE
        End With
        
    On Error GoTo 0

End Sub

Private Sub AppEvent_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As Boolean)
On Error Resume Next
            With Application
               .CommandBars("Cell").Controls("Google Search").Delete
            End With
    On Error GoTo 0
End Sub
module (modApplication)
Code:
Option Explicit
  Dim myAppEvent As New Class1
      Sub InitializeAppEvent()
          Set myAppEvent.appevent = Application
      End Sub

module (googleSearch)
Code:
Sub SearchGoogleIE()
    Dim ie As InternetExplorer
   
    Set ie = New InternetExplorer
    Dim query As String
    query = ActiveCell.Value
    'Search google
    ie.Navigate "http://www.google.com/search?hl=en&q=" & query & "&meta="
    ie.Visible = True
    Set ie = Nothing
End Sub
Added also Microsoft Internet Controls to references.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,224,596
Messages
6,179,802
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top