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):
module (modApplication)
module (googleSearch)
Added also Microsoft Internet Controls to references.
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
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