VBA website login

stethoscoop

New Member
Joined
Nov 13, 2015
Messages
9
I wrote a piece of code to open a website and log in on the website.
I used different variantions of the code with the help of these two topics:
http://www.mrexcel.com/forum/<wbr>excel-questions/461524-visual-<wbr>basic-applications-open-<wbr>website-logon-username-<wbr>password-3.html
http://www.mrexcel.com/forum/<wbr>excel-questions/465434-web-<wbr>username-password-form-submit.<wbr>html#post2297790
no matter what i try, it won't work. The website opens, but the username/password is not filled in.

I will show you two variations of my multiple attempts:
My first attempt:
Code:
Sub Test()




      Set IE = CreateObject("InternetExplorer.application")
      IE.Visible = True
      IE.navigate ("https://www.atosi.nl")
      Do
          If IE.ReadyState = 4 Then
              IE.Visible = False
              Exit Do
          Else
             DoEvents
         End If
     Loop
     IE.Document.Forms(0).all("gacode").Value = "me"
     IE.Document.Forms(0).all("code").Value = "mypasssword"
     IE.Document.Forms(0).all("access").Value = "mypasssword"
     IE.Document.Forms(0).submit
End Sub
The problem with this code is that it automatically closes the website after loading.
Do
If IE.ReadyState = 4 Then
IE.Visible = False
Exit Do
Else
DoEvents
End If
Loop
When i delete this part. The website will stay open.



My final attempt:
Code:
Sub Test2()


    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.application")
    With IE
        .Visible = True
        .navigate ("www.atosi.nl")
        While .Busy Or .readyState <> 4: DoEvents: Wend
    .Document.getElementByID("form-input-field_gacode").Focus
    .Document.getElementByID("gacode").Value = "code"
    .Document.getElementByID("code").Focus
    .Document.getElementByID("code").Value = "username"
    .Document.getElementByID("access").Focus
    .Document.getElementByID("access").Value = "Password"
    
    .Document.all("submit").Click
        While .Busy Or .readyState <> 4: DoEvents: Wend
        Debug.Print .LocationUrl
    End With
End Sub
This opens the website normally, but it does not fill in the 'code', 'username' and 'password'

A piece of the html: (i deleted the brackets in front of the html, it kept messing up the post)
form action="/v30/" method="post" style="margin:0px">
label for="gacode">code:
input id="gacode" name="gacode" placeholder="code" class="form-input-field" type="text" value="">
label for="code">gebruikersnaam:
input id="code" name="code" placeholder="gebruikersnaam" class="form-input-field" type="text" value="">
label for="access">wachtwoord:
input id="access" placeholder="wachtwoord" name="access" class="form-input-field" type="password" value="">
input type="submit" class="submit-button" value="inloggen">
input type="hidden" value="http://www.atosi.nl" name="return">
input type="hidden" value="M-95371" name="maat">
input type="hidden" name="doit" value="1">
/form

Does anybody know what im doing wrong?
Thanks in advance!
 
The code I posted in post #6 worked for me.

My apologies for the late reply. I had no internet this weekend.
You are right, the code works for me too.
No idea why it did not work the first attempt.

Thank you very much for your help
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
After logging in i go to the next page, where i need to click an image in order to go to the next page.
The html code looks like this:

li class="tile size2x2 tilebrown image" style="background-image:url('../images/tile-overzicht-bedrijven.jpg');">
a href="oscompbrowse.php?_reset=1">
h1>Overzicht</h1><br>
h2>bedrijven »</h2>
/a>
/li>

now my code looks like this:
Code:
Sub Test()
   Dim ele As Object
      
      'Openen website
      Set IE = CreateObject("InternetExplorer.application")
      IE.Visible = True
      IE.navigate ("https://www.atosi.nl/index.new.php")
      Do
          If IE.readystate = 4 Then
              Exit Do
          Else
             DoEvents
         End If
     Loop
     'Inloggen
     IE.document.Forms(0).all("gacode").Value = "Me"
     IE.document.Forms(0).all("code").Value = "Mypassword"
     IE.document.Forms(0).all("access").Value = "Access"
     IE.document.Forms(0).submit
     


'Pause while page loads


Do Until IE.readystate = 4
DoEvents
Loop


'Click On image
' loop through all 'a' elements and find the one with the value "Yes"


For Each ele In IE.document.getelementsbytagname("a")
If InStr(ele.innerhtml, "oscompbrowse.php?_reset=1") > 0 Then
ele.Click
Exit For
End If


Next
     
End Sub

The login part works (thanks again for that Norie), but for the part of clicking the image, nothing happens. I don't get an error or anything.
Does anybody know what i did wrong?
 
Last edited:
Upvote 0
I found a way to work around the login, so i can skip the step of clicking the image.
So this issue is resolved.

Thanks for all the help!
 
Upvote 0
Hi guys,

I tryed to adpt Norie's code for another website, but it doesn't work. The web site is AIS Vessel Tracking - AIS Positions Maps | AIS Marine Traffic .

The error is '424' object required and I think it's becase of [.all("data").] .

[CODE]

Sub Test()

Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
ie.navigate ("http://www.marinetraffic.com/en/users/login")
Do
If ie.readyState = 4 Then
ie.Visible = True
Exit Do
Else
DoEvents
End If
Loop
ie.Document.Forms(0).all("data[email]").Value = "me"
ie.Document.Forms(0).all("password").Value = "mypasssword"
ie.Document.Forms(0).submit

End Sub

[/CODE]


Could you please help me?
Thanks in advanced,
A
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,131
Members
449,097
Latest member
mlckr

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