VBA - Auto login to website

ashk0812

New Member
Joined
Sep 27, 2019
Messages
9
Greetings,

I wonder if anyone could help me please I am trying to put together a macro to log into a website. This is the code I currently have,

Code:
Sub IE_LOGIN_NEWLINE()
Dim appIE As Object: Set appIE = CreateObject("InternetExplorer.Application")
With appIE
    .navigate "https://dhl-sequencecheck.newlinecomputing.net/api/index.html#/"
    Do While .Busy Or .ReadyState < 4: DoEvents: Loop
    .Visible = True
    
    .Document.all.loginform.user.Name.Value = Sheets("Web").Range("E20").Value
    .Document.all.loginform.user.Password.Value = Sheets("Web").Range("E22").Value
    .Document.all.LoginForm_Submit.Click
    
End With
End Sub
I keep getting errors saying that object doesnt support this property or method. Ive inspected the elements but i dont really follow what im looking at.

any support that could be offered would be muchly appreciated
 

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,872
Office Version
2010, 2007
Platform
Windows
Hello ashk0812,

At first glance your URL "https://dhl-sequencecheck.newlinecomputing.net/api/index.html#/" is not a login page.

On which line is the error being generated?

HTML does not generally use Value. Instead, try innerHTML , like this...
Code:
.Document.all.loginform.user.Name.innerHTML = Sheets("Web").Range("E20").Value
.Document.all.loginform.user.Password.innerHTML = Sheets("Web").Range("E22").Value
 
Last edited:

ashk0812

New Member
Joined
Sep 27, 2019
Messages
9
Hello ashk0812,

At first glance your URL "https://dhl-sequencecheck.newlinecomputing.net/api/index.html#/" is not a login page.

On which line is the error being generated?

HTML does not generally use Value. Instead, try innerHTML , like this...
Code:
.Document.all.loginform.user.Name.innerHTML = Sheets("Web").Range("E20").Value
.Document.all.loginform.user.Password.innerHTML = Sheets("Web").Range("E22").Value
The error hits at
.Document.all.loginform.user.Name.innerHTML = Sheets("Web").Range("E20").Value

as for the url not being a login page I am not following what you mean by that?
 

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,872
Office Version
2010, 2007
Platform
Windows
Hello ashk0812,

The URI (the end part of the URL) "/
index.html#/" is commonly used to indicate a selection of pages. A login page looks like "/login?/".
 

ashk0812

New Member
Joined
Sep 27, 2019
Messages
9
Oh, I did not know that I dont really follow how it all works but when i go to that url and type in my username and password and hit login it logs in so im not sure how that would react to automation
 

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,872
Office Version
2010, 2007
Platform
Windows
Hello ashk0812,

Okay, I stand corrected. Well, it could be the "form" is being generated using Java after the page the displayed. Can you post a screen shot of the page?
 

ashk0812

New Member
Joined
Sep 27, 2019
Messages
9
Sure heres the screen shot

I wonder if i have the ids wrong? thing is im not sure what i should be using

Code:
<input type="text" placeholder="name" ng-model="user.Name" required="" class="ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched">
 

Leith Ross

Well-known Member
Joined
Mar 17, 2008
Messages
1,872
Office Version
2010, 2007
Platform
Windows
Hello ashk0812,

This Login Form uses JavaScript. Internet Explorer will return only the Client side information. That is, the basic structure of the web page returned by the site. The Login Form is added after the page has been made available to the client.

You probably could Login in using the MSXML2.ServerXmlHttp object. This method also uses login credentials but is not as simple a construct as IE.
 

ashk0812

New Member
Joined
Sep 27, 2019
Messages
9
Ok that just went over my head I will just assume its not possible at this time.

thank you for your assistance and time
 

footoo

Well-known Member
Joined
Sep 21, 2016
Messages
2,672
This should enter the username and password:
Code:
Sub IE_LOGIN_NEWLINE()
Dim e As IHTMLElement, elems As Object
Dim appIE As Object: Set appIE = CreateObject("InternetExplorer.Application")
With appIE
    .navigate "https://dhl-sequencecheck.newlinecomputing.net/api/index.html#/"
    Do While .Busy Or .readyState < 4: DoEvents: Loop
    .Visible = True
    Set elems = .document.getElementsByTagName("input")
    For Each e In elems
        If e.Type = "text" Then
            e.Value = Range("E20").Value
        Else
            e.Value = Range("E22").Value
        End If
    Next
End With
End Sub
I couldn't work out how to click the Login button.
Perhaps someone can have a go.
 
Last edited:

Forum statistics

Threads
1,082,585
Messages
5,366,466
Members
400,892
Latest member
lamarh755

Some videos you may like

This Week's Hot Topics

Top