Open google with sendkey

zin1994

New Member
Joined
Aug 19, 2016
Messages
5
Hello,

Below is the code I have been working on to open up google using send keys. Normally I use the waitime function I made below to guess when a page has loaded all the way. However sometimes the web page takes longer to open than other times. Is there any way that I can make the loop I have placed in the code work as a way of waiting until the page is loaded before it starts going down the list of send keys? Any help is appreciated! thanks in advance!
Code:
Sub openTest()
    
    file_path = "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
    
    Call Shell(file_path, vbNormalFocus)
    Do
    Loop Until file_path.readyState = READYSTATE_COMPLETE
   
    Call SendKeys("^e", True)
    Call SendKeys("+{TAB}", True)
    waitTime (2000)
    Call SendKeys("www.google.com", True)
    Call SendKeys("{ENTER}", True)
    
End Sub
    
Function waitTime(ByVal milliSeconds As Double)
    Application.Wait (Now() + milliSeconds / 24 / 60 / 60 / 1000)
End Function
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Thank you so much for sending to that forum, however I still have a question. Can you help me get the following code to run. I feel like I am very close.
Code:
Sub googlesearch()
Set objIE = CreateObject("InternetExplorer.Application")
WebSite = "www.google.com"
With objIE
.Visible = True
.navigate WebSite
Do While .Busy Or .readyState <> 4
DoEvents
Loop

Set Element = .document.getElementsByName("q")
Element.Item(0).Value = "hi"
.document.forms(0).submit

'The  above is what I want to happen first then I want the page to wait until  the page loads all the way then I wan it to execute what is below

Do While .Busy Or .readyState <> 4
DoEvents
Loop

Set Element = .document.getElementsByName("q")
Element.Item(0).Value = "hi again"
.documnet.forms(1).submit
.Quit
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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