Login to a website from VBA

Yulyo

Board Regular
Joined
Jul 17, 2017
Messages
94
I am trying to login to a website through a VBA. The VBA completes the username and password, but won't click the submit button.

This is my VBA:

Code:
Sub Login()
     
    Dim ie As Object
     
    Set ie = CreateObject("InternetExplorer.Application")
     
    ie.navigate "www.something.com"
     
    ie.Visible = True
     
    Do While ie.Busy And Not ie.readyState = 4
        DoEvents
    Loop
     
    DoEvents
  
    ie.document.all.Item("username").Value = "xxx"
    ie.document.all.Item("password").Value = "yyy"
    ie.document.all.Item("submit").click
     
End Sub



When i inspect the "Go" button, this is what i have:

input width="200" type="submit" value="Go"

Any help please?
Thanx
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try this and see if it works;

Code:
    Set HTML_Elements = ie.document.getElementsByTagName("input")
    For Each Button_Element In HTML_Elements
        If (Button_Element.getAttribute("value") = "Go") Then
            Button_Element.Click
            Exit For
        End If
    Next
 
Upvote 0
Hello,

I have used the VBA Code above and fitted it for the application I need. So far I have been able to get the webpage to open, enter my userID and my password. What I am having difficulty with is getting the "Sign in" button to click.

Here is my code

Sub Login()

Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")

ie.navigate "https://website.com"

ie.Visible = True

Do While ie.Busy And Not ie.readyState = 4
DoEvents
Loop

DoEvents

ie.document.all.Item("txtUser").Value = "UserID"
ie.document.all.Item("txtPass").Value = "password"
ie.document.all.Item("__doPostBack('Login','')").Click

End Sub


The error I am getting is
"Run-time error '91':"
Object variable or with block variable not set

I have no idea how to fix this and make the code work. Can anyone please help?

Thank you - Jim
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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