Need experts advice. Please help me on how to improve my sendkey code:

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi,
For now it opens the site but it does not enter the word to search.
There is no error message as such. I did not use sendkey{TAB} sendkey {%tab} because google set focus on search field when
we open the site...

Please advice on how to copy range("A1")value to google and hit enter.
Thank you so much in advance.

Pedie;)
Code:
Sub try()
Dim ie As InternetExplorer
    Dim MyStr As String
    Set ie = New InternetExplorer
    ie.Navigate "[URL="http://google.com/"]http://google.com[/URL]"
    ie.Visible = True
    Application.Wait Now + TimeValue("00:00:01")
    SendKeys "%{tab}"
    sheet1.Range("A1").Copy
    SendKeys "%{tab}"
    SendKeys "{tab}"
    Application.SendKeys ("^v")
    Application.SendKeys "%{Enter}"
End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try something like this...

Code:
Sub try()

    Dim ie As InternetExplorer  ' Set reference Microsoft Internet Controls

    Set ie = New InternetExplorer
    
    ie.Navigate "http://www.google.com/search?hl=en&q=" & [COLOR="Red"]Sheet1.Range("A1").Text[/COLOR] & "&meta="
    
    'Loop unitl ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop
    
    ie.Visible = True

End Sub
 
Upvote 0
Hey Alpha!

Wow, it actually worked!(y).
This is great....It was totally new..so more better!

Please allow me to ask one more question..

Is there any simplier way? I mean if i have to apply this to other site where it is not a search but where I need to hit tab once and then hit enter after entering a word?

And thank you so much for quick reply.
Regards
Pedie;)
 
Upvote 0
Try adding a slight delay after each sendkey command

e.g:
QUOTE]

Hi Shigueo, please advice as to where exactly do i use those delay code?
I am really new to this codes....
Also please read my above post.

Thanks again.
Waiting for you guys for more help...:)
 
Upvote 0
This will send TAB & A1.text & ENTER

Application.SendKeys ("{TAB}" & Sheet1.Range("A1").Text & "{ENTER}")
 
Upvote 0
Apha, thanks you so much once again
This code seems to be working but there is one more problem. This tab key does not tab down to htmltextbox....

I did try manually (myself without the code) to tab next down from address bar then it does not tab cross the web address. When i hit tab it just remains in web address

Is there a way to tab through the web address? Or can the code act like it click on the web page apart from the address bar?

Thanks again!


Code:
Sub try101()
    Dim ie As InternetExplorer  ' Set reference Microsoft Internet Controls
    Set ie = New InternetExplorer
    'http://www.google.com/search?hl=en&q=VBA%20EXCEL%20SENDKEYS&meta=
 
    ie.Navigate "my site.."
    Application.Wait Now + TimeValue("00:00:01")
    Application.SendKeys "%{TAB}"
 
    Range("A1").Copy
 
    Application.SendKeys "%{TAB}"
 
    Application.Wait Now + TimeValue("00:00:01")
    Application.SendKeys "{TAB}"
    'SendKeys "{TAB}"
    Application.SendKeys ("^v")
    Application.SendKeys "%{Enter}"
 
    'Loop unitl ie page is fully loaded
    Do Until ie.readyState = READYSTATE_COMPLETE
    Loop
 
    ie.Visible = True
 
End Sub
 
Last edited:
Upvote 0
Go to your web page in IE.
From the IE menu, select View\ Source
You will see the HTML code for that web page. In that code will be IDs for the components like input boxes and buttons on that page. They will have string IDs like id="loginButton" or id="loginusername".

You can interact with those specific components like this...

Code:
Sub try()

    Dim ie As InternetExplorer  ' Set reference Microsoft Internet Controls

    Set ie = New InternetExplorer
    
    ie.Navigate "http://...."
    '"http://www.google.com/search?hl=en&q=" & Sheet1.Range("A1").Text & "&meta="
    
    'Loop unitl ie page is fully loaded
    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop
    
    ie.Visible = True
    
    ie.Document.getElementById("[COLOR="Red"]loginusername[/COLOR]").Value = "UserIDHere"
    ie.Document.getElementById("[COLOR="Red"]userpassword[/COLOR]").Value = "Password here"
    ie.Document.getElementById("[COLOR="Red"]loginButton[/COLOR]").Click
    

End Sub

...but you have to use the ID strings specific to your web page.
 
Upvote 0
Error here in firstline...sorry i was away for a while...:)

ie.Document.getElementById("loginusername").Value = "UserIDHere"

incase this help:
when i recorded using web query this is how the code looks like
Code:
[/I]
Sub Macro1()
'
' Macro1 Macro
'
'
    Range("A3").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;https://........mysitename", Destination:= _
        Range("$A$3"))
        .Name = "3171"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    Range("A3").Select
End Sub
 
[I]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,931
Messages
6,133,586
Members
449,816
Latest member
amahmud1

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