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>
 
Sorry With the ctrl G question I meant did you mean to bring up the immediate box on the VBA screen.

I did look at the source code and there was no text about a form just tables. Are these the same things?
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I am making the assumption that there is only 1 form as changing the form number just sends up an error.
There's no need for you to make any assumptions because you have access to the HTML code, I don't. Look at the HTML source and count the number of < form > tags (each with a corresponding < /form> closing tag).

The code should wait (in bold) for the page to complete after the first submit:
Rich (BB code):
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
    While IE.Busy Or IE.readyState <> 4: DoEvents: Wend

    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
 
Upvote 0
I did look at the source code and there was no text about a form just tables. Are these the same things?
No, they aren't the same things. Your first post said the button was in this HTML:
HTML:
<input type=submit value="Login Succeeded - Click to Continue">
I'm fairly sure that INPUT tags can only occur within FORM tags, so there should be at least one < form > tag.
 
Upvote 0
Have you made sure everything has been loaded?

If you don't you might actually still be looking at the login page, not the continue page.

Here are examples of other code that will wait for the page to load/be ready etc.
Code:
    Do While IE.Busy: DoEvents: Loop
 
    Do While IE.ReadyState <> 4: DoEvents: Loop
 
    Set doc = IE.document
 
    Do While doc.ReadyState <> "complete": DoEvents: Loop
The last one waits for the actual document to complete loading.

PS Did you try my one line shot in the dark?
 
Upvote 0
I have inserted a delay into the code as above and all seems to work fine, now for selecting the correct table to update.

Thanks again.
 
Upvote 0
Next problem people sorry.

I have access the correct page of the website now and have loaded the table that I want to copy. there is again only one form on the page is there an easy way to select and paste this?
 
Upvote 0
Select and paste what?

If you mean a table and you want rge data from it there are various ways to do that.

By the way, which delay did you add?
 
Upvote 0
I used the first one you said about. It is a table that want to copy and paste to a sheet in the workbook.
 
Upvote 0
Well you can send select and copy commands to IE if you do want to copy and paste.

That would probably involve the whole page and to get the data you want you would need code to parse it out.

If you actually just want the data from the table you could use the page document object.

With that you can access all the elements on the page, including any tables.

So you just grab a reference to the table you want, pull the data from it and put it in worksheet.
 
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,476
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