Automating password access to web pages with VBA

RustB

New Member
Joined
Dec 8, 2016
Messages
3
Hello
I've had success accessing some user / password protected web sites with the following code but this website has got me scratching my head. I'm sure its an old problem but I can't find an existing forum conversation that helps. I got the element names from the webpage source code and wondering what I'm doing wrong.

Can anyone help please?

Many thanks in advance

Sub pwsite()
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "https://www.bloodhound.net.au/"
Do Until .ReadyState = 4
DoEvents
Loop

ie.Document.all("user_id").Value = "uuuuuuuu"
ie.Document.all("password").Value = "ppppppppp"
ie.Document.all("login").Click
End With
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Set Reference to Microsoft HTML object library and Microsoft Internet Controls before running below code:


Code:
Sub Ombir_09Dec2016()
Dim ie      As InternetExplorer
Dim doc     As HTMLDocument

Set ie = New InternetExplorer

With ie
    .Navigate "https://www.bloodhound.net.au/"
    .Visible = True
    Do While .ReadyState <> 4: DoEvents: Loop

    Set doc = .Document.getElementsByTagName("iframe")(0).contentDocument
   
    With doc
        .getElementsByName("user_id")(0).Value = "Rust"
        .getElementsByName("password")(0).Value = "RustBPassword"
        .getElementsByName("login")(0).Click
    End With
End With
ie.Quit
End Sub
 
Upvote 0
Many Thanks Ombir ... Awesome
I tried your code and at first it rejected the dim and set internet explorer lines but when I modified those it worked perfectly.
Here's what I ended up with. I also left the quit off the end also because I need to carry on and extend the code to do stuff on the page I sign onto.
This is my first time on the forum and I'm so impressed. Thanks again!!

Set ie = CreateObject("InternetExplorer.Application")
<strike>Dim ie As InternetExplorer</strike>
Dim doc As HTMLDocument

<strike>Set ie = New InternetExplorer</strike>

With ie
.Navigate "https://www.bloodhound.net.au/"
.Visible = True
Do While .ReadyState <> 4: DoEvents: Loop

Set doc = .Document.getElementsByTagName("iframe")(0).contentDocument

With doc
.getElementsByName("user_id")(0).Value = "UUUUUU"
.getElementsByName("password")(0).Value = "PPPPPP"
.getElementsByName("login")(0).Click
End With
End With
 
Upvote 0
Many Thanks Ombir ... Awesome
I tried your code and at first it rejected the dim and set internet explorer lines but when I modified those it worked perfectly.
End With


You didn't read my my first line carefully in post 2. I used the early binding. So you have to set references to these libraries from VBE Editor----->>Tools----->References
 
Upvote 0
Yes Sorry Ombir, I set the reference to HTML object Library but not the Microsoft Internet Controls as you point out.
I just did that and now it works exactly as you intended.
Thanks Again that is really great.
Regards
RustB
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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