Enter username and password in login form on a webpage RRS feed

  • Question

  • Using Excel VBA, I'm trying to login to a website.

    This is my code:

    Dim HTMLDoc As HTMLDocument
    Dim oBrowser As InternetExplorer
    Sub Website_Login()
    Dim oHTML_Element As IHTMLElement
    Dim sURL As String
    sURL = ""
    Set oBrowser = New InternetExplorer
    'oBrowser.Silent = True
    'oBrowser.timeout = 60
    oBrowser.navigate sURL
    oBrowser.Visible = True
    Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE
    Set HTMLDoc = oBrowser.Document
    With HTMLDoc
      HTMLDoc.getElementById("username").Value = "user"
      HTMLDoc.getElementById("password").Value = "password"
    End With
    For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
      Exit For
    End Sub

    The Javascript instructions in this code are working. If I go to the page and enter them, they work. But when I run the code, IE opens but it doesn't enter the user/pass and click the button.

    Any help, please?

    Tuesday, November 10, 2015 7:47 PM

All replies