Internet Explorer webpage - login and password

kacper887

New Member
Joined
Feb 12, 2018
Messages
6
Hello,

I have a website, for which I would like to write a macro for providing username and password, and log in with specific credentials. The website is written in JavaScript language. I am using MS Excel 2016, IE v11.

Here is my current code (I needed to provide "xxx" where necessary):

Code:
Sub IELogon()
' open IE, navigate to the desired page and loop until fully loaded
    Set IE = CreateObject("InternetExplorer.Application")
    my_url = "[URL]http://xxx[/URL]"
    With IE
        .Visible = True
        .Navigate my_url
        .Top = 50
        .Left = 530
        .Height = 400
        .Width = 400
    Do Until Not IE.Busy And IE.readyState = 4
        DoEvents
    Loop
    End With
' Input the userid and password
    IE.Document.getElementById("userid").Value = "xxx"
    IE.Document.getElementById("password").Value = "xxx"
' Click the "Login" button
    IE.Document.getElementById("Login").Click
    Do Until Not IE.Busy And IE.readyState = 4
        DoEvents
    Loop
End Sub

Unfortunately, my macro stops at:

Code:
.Navigate my_url


I will be grateful for any help! :biggrin:
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

When you say it stops at my_url does anything happen. IE launch, error messages?

It navigates to any URL I put in.
I'm using 2013 with IE11
 
Upvote 0
Okay, now I've changed the website URL a little bit, and the code opens IE, goes to the desired website, and it stops at:

Code:
Do Until Not IE.Busy And IE.readyState = 4

showing a run-time error
 
Upvote 0
I have little knowledge of using IE to access the web so I am looking for obvious issues such as not using the correct URL : )
There are 2 do while loops in your code?
Step through the code using F8 and see which one it is stopping at.

The first loop is merely looking for the page to report it has loaded and IE is in a ready state for another command.
If it is sticking at that I haven't a clue why as I don't have the URL/Web page to look at.
A possible cause of a failure though is running scripts.

If it is the second Do Until: I'm not sure you need it for a login.
I would remove it and try again.

Does what you look for in the login match the fields in the webpage?


There are plenty of examples for code for logging into websites with vba if you google:
'VBA to login to a website'
'vba input username and password for IE'
 
Upvote 0
Thanks for help anyway! Now, after several analysis, I know that my code was totally wrong. Nevertheless, I've managed to write a new one, which is working :cool:

By "is working" I mean that it is opening desired website without any errors. So the current scenario, when the code is ending its work, is:

1. Internet Explorer is open and active.
2. Desired website is open.

Below I provide my current code:

Code:
Sub IE_Open_Website()

'Opening IE, navigating to the desired page and looping until fully loaded
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate ("website URL") '<<< Provide website URL
IE.Visible = True


'Changing Shell setting in the background to avoid IE error
Set IE = Nothing
Set objShellApp = CreateObject("Shell.Application")
For Each objWindow In objShellApp.Windows
    Debug.Print objWindow.LocationName
     If LCase(objWindow.LocationName) = LCase("Your windows name, use debug to find out") Then '<<< Provide windows name
            Set IE = objWindow
            
     End If
Next
End Sub


Now my intention is to:

1. Use obj reference (maybe other reference?) in VBA to add to macro "memory" specific fields: "User ID:", "Password:" - credentials will be provided in these two.
2. Enable providing specific text values in "User ID:" & "Password:" (credentials).
3. Enable my code to push the "Login" button on my website after providing credentials.

I will appreciate any help in this matter.

Thanks in advance!
 
Upvote 0

Forum statistics

Threads
1,215,884
Messages
6,127,561
Members
449,385
Latest member
KMGLarson

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