Website access with a password

mummbles74

Board Regular
Joined
Nov 14, 2009
Messages
120
Office Version
  1. 365
Platform
  1. Windows
I have managed to get access to a webiste using VBA ready to access the data table that I need to copy to a spread sheet, before I attempt this I am getting stuck after I have entered the username and password.

I am using the code below:

Sub Test()
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
ie.Navigate2 "extranet.deritend.co.uk/portal/login.php"
Do
If ie.readyState = 4 Then
'ie.Visible = False
Exit Do
Else
DoEvents
End If

Loop
ie.document.forms(0).all("Username").Value = "me"
ie.document.forms(0).all("Pin").Value = "password"
ie.document.forms(0).submit
end sub

And all works fine until the next page on the website loads, all it is normally is a page with the standard site header and 1 grey box that you need to click on to access the main part of the website. I have viewed the source code but the button is not named so have no idea how to "click" it using VBA code.

Any ideas?

This is the source code for the button that I can not select ( I have removed the < from the begining of each line so that it does not creat a picture on here, hopefully)

table>
tr><td>
input type=submit value="Login Succeeded - Click to Continue">
/td></tr>
/table>
br>

Thanking you in advance as always

Please Help!!
<FORM action=index.php method=post target=_parent> </FORM>
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I have viewed the source code but the button is not named so have no idea how to "click" it using VBA code.
HTML:
<input type=submit value="Login Succeeded - Click to Continue">
Loop through the form's input elements looking for the submit button, something like this:
Code:
    Dim inputElement As HTMLInputElement

    For Each inputElement In IE.document.forms(0).elements
        If inputElement.Type = "submit" And inputElement.Value = "Login Succeeded - Click to Continue" Then
            inputElement.Click
            While IE.Busy Or IE.readyState <> 4: DoEvents: Wend
            Exit For
        End If
    Next
The code needs a reference to Microsoft HTML Object Library; Tools - References in the VBA project.

NB - Surround HTML code with [ HTML] [ /HTML] tags without the spaces.
 
Upvote 0
I have inserted the code you provided into my original code but still seem to have no luck. I really know nothing of HTML code but it almost seems that the box is not set up as any sort of input.
 
Upvote 0
Firstly, the code assumes that the input button is in the first form - forms(0). Is that correct? Determine the number of forms on the page by typing ?IE.document.forms.Length in the Immediate window, or as a Debug.Print statement.

Secondly, try debugging with F5, F8, etc, and setting appropriate breakpoints. Add this before the If statement:
Code:
        Debug.Print inputElement.Type, inputElement.Name, inputElement.Value
 
Upvote 0
Where's the actual problem, logging in or with the continue button?
 
Upvote 0
Surely this is the only button on the form.
Code:
ie.Document.GetElementsByTagName("INPUT")(0).CLick
By the way, I doubt John's code didn't do anything.

Try opening the immediate window (CTRL+G) after (or even during) it.

One other thing, if you pass the
 
Upvote 0
John

I am making the assumption that there is only 1 form as changing the form number just sends up an error. Entering the code that you provided before the If statment seems to do nothing different (I assume I am doing something wrong).

I have copied in the code I now have.

Sub Test()
Dim inputElement As HTMLInputElement
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.Navigate2 "extranet.deritend.co.uk/portal/login.php"
Do
If IE.readyState = 4 Then
'IE.Visible = False
Exit Do
Else
DoEvents
End If

Loop
IE.document.forms(0).all("Username").Value = "P"
IE.document.forms(0).all("Pin").Value = "password"
IE.document.forms(0).submit
For Each inputElement In IE.document.forms(0).elements

Debug.Print inputElement.Type, inputElement.Name, inputElement.Value

If inputElement.Type = "submit" And inputElement.Value = "Login Succeeded - Click to Continue" Then
inputElement.Click
While IE.Busy Or IE.readyState <> 4: DoEvents: Wend
Exit For
End If
Next

End Sub

Thanks for the continued help
 
Upvote 0
Norrie

Yes it is the only button on the page.

Trying your code instead off and with johns code still seems to get me know further.

excuss my ignorance but I am by no way an expert with VBA etc, what did you mean by ctrl G?
 
Upvote 0
CTRL+G means press the control button and the g key at the same time.

Have you considered that there might not be any forms on the page.

That's unlikely since I think you are dealing with ASP pages but you never know.:)
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

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