Run-time error 13 'Type Mismatch' in getElementByID RRS feed

  • Question

  • Hello VBA Gurus, I am a beginner and here is the problem I am encountering.

    I am trying to automate web login using VBA in Excel and I am getting runtime error 13 pop up.

    I have used codes found across different websites and here it is. Any help will be appreciated.

    Sub test()
    ' open IE, navigate to the desired page and loop until fully loaded
        Dim IE As InternetExplorerMedium
        Set IE = New InternetExplorerMedium
        my_url = ""
        With IE
            .Visible = True
            .Navigate my_url
        Do Until Not IE.Busy And IE.readyState = 4
        End With
    'no error till this point. Run Time error 13 appears because of following code
        Set UserName = IE.Document.getElementById("login_usr")
        UserName.Value = "ABCDE"
        Set Password = IE.Document.getElementById("login_password")
        Password.Value = "ABCDE"
        Set btnLogin = IE.Document.getElementById("Login")
    End Sub

    Please look at the second comment line. I have been able to localise the error to this block of code.

    Looking forward to your advice.


    Tuesday, April 5, 2016 12:33 AM

All replies