Consulting

Results 1 to 6 of 6

Thread: API Calls or VBKey Commands in IE

  1. #1

    Exclamation API Calls or VBKey Commands in IE

    Hi

    Recently I was querying about how to automate certian things in Internet Explorer on this site, I have read up about it since and thought about this...

    Is there was a way to use the VBkeyReturn to actually press enter in an Input Box rather than the ASCCI Number or if there was a way to use API call to press enter in an Input box, basically I want to use it in this example below but I'm not allowed to use the Buttons on the website as this is a test version of something with no buttons.

    I have used SendKeys but they have a low success rate and I really mustn't use them for my code.

    I would also need to get something to prevent the code going to fast, I used Sleep which works well, but sometimes the sleeps need to vary in time so I wondered can you get something to detect when the web page is ok to continue with the code.

    This is the code which also uses the Internet Controls Reference, also you would need to disable the "Instant On" feature on the Google page...

    [vba]
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Sub Auto()
    Dim ie As InternetExplorer
    Set ie = New InternetExplorer

    ie.Navigate www.Google.co.uk

    Do Until ie.ReadyState = READYSTATE_COMPLETE
    Loop

    ie.Document.all("q").Value = "Chacanger"
    SendKeys "ENTER", True
    Sleep 200
    ie.Document.all("q").Value = "Random Text"
    SendKeys "ENTER", True
    Sleep 200
    ie.Document.all("q").Value = "More Random Text"
    SendKeys "ENTER", True
    Sleep 200

    ie.Document.all("q").Value = "Another Random Text"
    SendKeys "ENTER", True
    Sleep 200
    ie.Quit
    Set ie = Nothing

    End Sub
    [/vba]

    Thanks in advance for any help.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    To answer the first part of your question:
    [vba]ie.Document.all("f").submit[/vba]and you don't need to turn off "Instant On"
    For the second part, the following worked with Instant On:
    [vba]Sub Auto()
    Dim ie As InternetExplorer
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "www.Google.co.uk"
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    ie.Document.getElementById("q").Value = "Chacanger"
    ie.Document.getElementById("f").submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    ie.Document.getElementById("q").Value = "Random Text"
    ie.Document.getElementById("f").submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    ie.Document.getElementById("q").Value = "Something"
    ie.Document.getElementById("f").submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    ie.Document.getElementById("q").Value = "Automate"
    ie.Document.getElementById("f").submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    'stop

    ie.Quit
    Set ie = Nothing
    End Sub
    [/vba] [the automatic indentation has gone ape]
    If Instant Off, use "gs" instead of "f". I think.

    If I find how to detect whether it's on or off I'll post again.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Found out how to circumvent Instant On/Off changing the name of the form to submit: Don't use the name, it's a child of the "q" element, so the following works regardless of Instant On/Off:[VBA]Sub Auto2()
    Dim ie As InternetExplorer
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "www.Google.co.uk"
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "Chacanger"
    theform.form.submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "something"
    theform.form.submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "automate"
    theform.form.submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "can't think"
    theform.form.submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Stop

    ie.Quit
    Set ie = Nothing
    End Sub[/VBA]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    Quote Originally Posted by p45cal
    Found out how to circumvent Instant On/Off changing the name of the form to submit: Don't use the name, it's a child of the "q" element, so the following works regardless of Instant On/Off:[vba]Sub Auto2()
    Dim ie As InternetExplorer
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "www.Google.co.uk"
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "Chacanger"
    theform.form.submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "something"
    theform.form.submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "automate"
    theform.form.submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "can't think"
    theform.form.submit
    Do Until ie.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not ie.Busy

    Stop

    ie.Quit
    Set ie = Nothing
    End Sub[/vba]
    Thanks p45cal for this, I'll see if I can get my ASPX to work with this and I'll post back with what results I get.

  5. #5

    Thumbs up

    Quote Originally Posted by chacanger
    Thanks p45cal for this, I'll see if I can get my ASPX to work with this and I'll post back with what results I get.
    I tried it against a hidden name within my ASPX page and it works!

    Hurrah!!!

    Is there a way you can refer to the Do...Loop rather than have to keep retyping lines with the same Do...Loop?

    Thanks so much for your help.

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    [quote=chacanger]Is there a way you can refer to the Do...Loop rather than have to keep retyping lines with the same Do...Loop?[/quote
    Put those lines in a sub:[vba]Sub waitTilReady(iiee)
    Do Until iiee.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
    Do: DoEvents: Loop Until Not iiee.Busy
    End Sub
    [/vba] then either:
    [vba]Sub Auto2()
    Dim ie As InternetExplorer
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "www.Google.co.uk"
    waitTilReady ie

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "Chacanger"
    theform.form.submit
    waitTilReady ie

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "something"
    theform.form.submit
    waitTilReady ie

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "automate"
    theform.form.submit
    waitTilReady ie

    Set theform = ie.Document.getElementByid("q")
    theform.Value = "can't think"
    theform.form.submit
    waitTilReady ie

    Stop

    ie.Quit
    Set ie = Nothing
    End Sub
    [/vba] or:
    [vba]Sub Auto3()
    Dim ie As InternetExplorer
    Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "www.Google.co.uk"
    waitTilReady ie
    TextArray = Array("Chacanger", "something", "automate", "can't think")
    For Each Strng In TextArray
    Set theform = ie.Document.getElementByid("q")
    theform.Value = Strng
    theform.form.submit
    waitTilReady ie
    Next Strng

    Stop

    ie.Quit
    Set ie = Nothing
    End Sub
    [/vba]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •