Need help opening IE browser and searching Google from Excel

Bones3640

New Member
Joined
Sep 5, 2017
Messages
1
I created a macro in VBA to open an Internet Explorer window, go to Google, and search Google based on what is the the active cell when you trigger the macro. The macro also Maximizes the IE browser window.

The problem is that the macro does not run correctly every time. Often it will go to Google but then not fire the search. Other times it will return an error.

I need help (1) making sure the macro runs correctly every time and (2) resizing the IE window to 1/4 of the screen and placing it in the top left corner of the screen.


Here is my code:

Declare Function apiIEsize Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long, ByVal CmdShow As Long) As Long


Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2




Sub Product_Search_1()
Dim MyItem As String, MyIe As Object, MyLoop As Object, MyElements As Object
MyItem = ActiveCell.Value
Set MyIe = CreateObject("InternetExplorer.Application")
MyIe.navigate "www.google.com"
While MyIe.busy = True
Wend


Set MyElements = MyIe.document.getElementsbyTagName("Input")
For Each MyLoop In MyElements
If MyLoop.Name = "q" Then: MyLoop.Value = MyItem
If MyLoop.Value = "Google Search" Then
MyLoop.Focus
MyLoop.Click
MyLoop.fireevent ("onsubmit")


End If
Next MyLoop
MyIe.document.getelementbyid("_fZl").Click
MyIe.document.getelementbyid("lst-ib").Value = MyItem


MyIe.Visible = True
apiIEsize MyIe.hwnd, 3








End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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