Consulting

Results 1 to 2 of 2

Thread: sendkeys question

  1. #1
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location

    sendkeys question

    hi,

    i'm need to access an intranet website which requires me to navigate 3 screens before i get to the screen to input data and evoke a query.

    i can access the site but i'm having trouble with the 1st screen. there's a button that says LOGIN that i can click or i can tab 2 times and hit the enter key.

    i don't know how to evoke a button click so i tried using SendKeys but i can't seem to get that to work.

    this is from the source code:

    <center><a href="InitialLogin.jsp">Login</a></center>
    </form> </div>


    here's my code so far
    [vba]Sub Intranet()
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    On Error GoTo 1
    With IE
    .Navigate "http://myintranetsite.jsp"
    .Visible = True

    AppActivate "Internet Explorer"
    SendKeys ("{TAB}")
    SendKeys ("{TAB}")
    SendKeys ("{ENTER}")

    End With

    Set IE = Nothing
    Exit Sub


    1: MsgBox Err.Description
    IE.Quit
    Set IE = Nothing

    End Sub[/vba]


    this will be the first of a few more questions one step at a time


    thanks
    zach

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    It is best to avoid Sendkeys. If you are using Vista, you will need to disable UAC for SendKeys to work.

    It would be better to use the internet explorer's object model to Submit the form rather than Sendkeys. You can iterate the doc's All collection and get the control for the "form" and submit it.

    In either case, notice how in the code, a loop makes the code wait until the page has loaded.
    [VBA] 'Norie, http://www.ozgrid.com/forum/showthread.php?t=69569
    ' http://www.mrexcel.com/board2/viewforum.php?f=2
    Sub Test()
    Dim lnk As Object, ie As Object, doc As Object, i As Long
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
    .Visible = True
    .Navigate "http://www.mrexcel.com/board2/viewforum.php?f=2"
    Do Until .readyState = 4: DoEvents: Loop

    Set doc = ie.document


    For Each lnk In doc.Links
    If lnk.Classname = "topictitle" Then
    i = i + 1

    Range("A" & i) = lnk.innertext
    Range("B" & i) = lnk

    End If
    Next lnk

    End With

    End Sub[/VBA]

Posting Permissions

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