vba login to internet

wxue

New Member
Joined
May 13, 2008
Messages
35
how can I login to a website using vba. I googled many examples but still failed. any one can help me? Thanks
 
Thanks for your replies Tom. That microsoft document was very confusing and thus not very helpful. I understand the idea behind POST, but I think it is much too complicated for me. If possible I would rather find a way to fill the entries like they are text boxes as the code provided in this thread suggests.

Why doesn't the code

Set UserIdbox = PageForm.elements("userid")

work to create the object? Based on the source information the id for the username should be "userid"...
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Nevermind. I figured out the problem. There was another form on the page that I was missing and had to change the form number. Thanks for your reply though.
 
Upvote 0
I'm running into the same problem trying to login to a website. I trie interpreting the source code, but I cannot tell what the login & password code names are.

I tried using an ieform(#).Value ="Username" approach. I was able to fill the appropriate text boxes for user name and password, but I'm not able to get the page to submit. I tried using ieform.submit, and it appears like it is going to work, but just refreshes and wipes out the password.

Any idea what I'm doing wrong? Thanks!
 
Upvote 0
First, You have to make sure you are on the right form number. I believe the default one is 0 and then it increases with every additional form on the page. Then just look for an input type <input> and the get the id value. An easy way to find it is to look at the actually web page and see what it says next to the input box. For example, in Gmail it says:

Username: [input box]
Password: [input box]

These have to be defined in the html code, so do a search for those and you should find the right input box close by! If you get stuck, send the webpage along and I can take a look.
 
Upvote 0
BPtexan

Any chance you could start a new thread?

If you do then it might be an idea to post the URL you are trying to work with - that's kind of important when trying to help with this sort of thing.:)
 
Upvote 0
Hi all,


I have a similar problem, but I have two options of accessing the file (sans VBA) - firstly, I could go via the webportal, enter my login details, and then click a link that leads to an .xls file that I would save down. Alternatively, I have the link directly to the file (this is static but the contents gets updated every day). When I use this link for the first time during the day it redirects to the login page, and after I've entered my details here it takes me straight to the Open/Save dialogue.


Is it possible to automate this using just the link and the login details? The URL is a https. Essentially I'd like to have code in place that (a) opens up the file, obviously logging in in the progress, (b) saves down the file with a timestamp (I've got the code down for this bit), and (c) closes the IE page.
 
Upvote 0
Hey lopiteaux,
My guess is that you need to enter your login details for the first time of the day and then after that it redirects you to the link automatically. You can probably use a similar code to what I've posted (adapted for your needs) and just add an IF statement to take care of the onetime login required.

Does that help at all?
DoubleDaffy
 
Upvote 0
Hi Daffy,
you're correct, yes, but unfortunately I'm still stuck - I have to admit I have no idea on how to tackle this one.

The website in question is https://www.theice.com/homepage.jhtml?loginApp=ICE, which after logging in, leads to a second page, https://www.theice.com/dashboards/ClearEuropeDashboard.shtml, from which I have to click a link to access the file located at https://www.theice.com/dashboards/clear_europe/securedocs/IDR_rates_USD_GBP_EUR.xls. This file is the one I'm after...

To stir things up even more, not only is there a login and password, but also a menu selection, from which I have to select "Clear EU Dashboard"...

I've pasted in your code below - no changes made I'm afraid. I'm really stuck on this one mate - your help is greatly appreciated!

Thanks

Code:
Sub RetrieveIDRReport_Test()
Const cURL = "[URL]https://www.theice.com/homepage.jhtml?loginApp=ICE[/URL]"
Const cUser = "USERNAME"
Const cPass = "PASSWORD"
'https://www.theice.com/dashboards/clear_europe/securedocs/IDR_rates_USD_GBP_EUR.xls
Dim ie As Object
Dim doc As HTMLDocument
Dim PageForm As HTMLFormElement
Dim UserIdBox As HTMLInputElement
Dim PasswordBox As HTMLInputElement
Dim FormButton As HTMLInputButtonElement
Dim Elem As IHTMLElement
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate cURL
'Wait for initial page to load
Do While ie.busy: DoEvents: Loop
Set doc = ie.document
'Output HTML tags to debug window
Debug.Print "Login page: " & ie.LocationURL
For Each Elem In doc.all
'Debug.Print Elem.tagName
Next
'Get the only form on the page
Set PageForm = doc.forms(0)
'Get the User Id textbox
'< input class="TextBox" maxlength="8" name="userid" size="8">
Set UserIdBox = PageForm.elements("userid")

'Set the User Id
UserIdBox.Value = cUser
'Get the password textbox
'< input class="TextBox" type="password" maxlength="10" name="Password" size="12">
Set PasswordBox = PageForm.elements("password")
'Set the password
PasswordBox.Value = cPass
'Submit the form (like clicking the 'Submit' button) to navigate to next page
PageForm.submit
'Wait for the new page to load
Do While ie.busy: DoEvents: Loop
'Get the HTML document of the new page
Set doc = ie.document
'Output HTML tags to debug window to prove this is the new page
Debug.Print "Terms of Use page: " & ie.LocationURL
For Each Elem In doc.all
'Debug.Print Elem.tagName
Next
'The new page contains 'Terms of Use' conditions and an 'Accept' button within a form
'Get the only form on the page
Set PageForm = doc.forms(0)
'Get the form submit button and click it to navigate to next page
'< input type="submit" value="Accept" name="selection">
'Note: unlike the login page, can't use PageForm.submit to submit this form because it doesn't have
'a method="post" attribute
Set FormButton = PageForm.elements("selection")
FormButton.Click
'Wait for the new page to load
Do While ie.busy: DoEvents: Loop
'Get the HTML document of the new page
Set doc = ie.document
'Output HTML tags to debug window to prove this is the new page
Debug.Print "Main Pronto page: " & ie.LocationURL
For Each Elem In doc.all
'Debug.Print Elem.tagName
Next
End Sub
 
Upvote 0
Lopiteaux,
Let's clear up the logic of what you want to do before we continue. If I understand it correctly:


  1. Open link
  2. If login is necessary do so.
    • This requires inputting a Username and Password and simulating a "click" on the "GO" button
    • Also need to select from the dropdown menu (which is do-able)
  3. Navigate to the next page
  4. Access the link for the correct page to download
  5. I'm then assuming you'll use the downloaded page for information to be inputted into Excel.
If that sounds right we can work through getting excel to navigate the HTML source code for your webpage to do all of this. It's not pretty, and its not very efficient, but it is possible.

Best,
~Doubledaffy
 
Upvote 0

Forum statistics

Threads
1,225,204
Messages
6,183,577
Members
453,170
Latest member
sameer98

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