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!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
In the first code why are you hiding IE in the loop?
Rich (BB code):
          If IE.ReadyState = 4 Then
              IE.Visible = False
              Exit Do
          Else
 
Upvote 0
You shouldn't have that line in there at all.

When you take it out what happens?

Do you get any errors or is there still nothing happening for the username/password?
 
Upvote 0
Oke thanks for the help so far, really appreciate the quick reply.
Deleting that bit of code changes nothing.

I always get an error around this line of code:
IE.Document.Forms(0).all("gacode").Value = "me"
The error is in dutch. I will try to translate it:
Error -21474672559 (80004005) during execution: Method document from object Iwebbrowser2 has failed.
 
Upvote 0
So something does happen, you get an error.:)

Just had a look at the source code behind the page and it appears to use frames.

There are 2 fames, the login form appears to be in one named 'index.new.php' and the other frame, named 'empty.php', appears to be, well, empty.

Try navigating to the frame with the form.
Code:
Sub Test()

      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
     
     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
 
Upvote 0
Try this:

Code:
Sub Open_IE()


Dim ie As Object
Dim frme As Object
Dim frm As Object
Dim i As Long



Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
ie.navigate "https://www.atosi.nl/"

While ie.busy
DoEvents
Wend



For i = 0 To ie.Document.Frames.Length - 1

If ie.Document.Frames(i).name = "mainFrame" Then
Set frme = ie.Document.Frames(i)
Exit For
End If
Next
Set frm = frme.Document.Forms(0)

frm.elements("gacode").Value = "test"
frm.elements("code").Value = "test"
frm.elements("access").Value = "test"

frm.submit


End Sub
 
Upvote 0
The code I posted in post #6 worked for me.
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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