Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Excel VBA html login

Posted on 2009-12-29
2
Medium Priority
?
400 Views
Last Modified: 2012-05-08
I am trying to use the following to login to a website where in later code Il scan the html page for relavant tags so to grab the data on the page. However, I am unable to get to the login object to enter my username and password str. Any help is much appreciated.


Sub Website()
'

Dim ie As Object, iebody As String, strURL As String, strUsername As String, strPassword As String

Set ie = CreateObject("InternetExplorer.Application")

strURL = "https://secure.ftinteractivedata.com/desktop/cgi/id-menus.cgi?ref=DM"
strUsername = "?"
strPassword = "?"

ie.Navigate strURL
'Wait until page is loaded.
While ie.ReadyState < 3  ' READYSTATE_COMPLETE = 4
    DoEvents
Wend
   
ie.Visible = True
       
ie.Document.All("Username:").Value = strUsername  ---> this is where I am running into an error.  The str text is not being filled onto the website.>
ie.Document.All("password").Value = strPassword
ie.Document.All("submit").Click
       
'Wait until page is loaded.
While ie.ReadyState < 3  ' READYSTATE_COMPLETE = 4
    DoEvents
Wend

Application.Wait (Now + TimeValue("0:00:05"))

iebody = ie.Document.body.innerhtml

If InStr(iebody, "The information you entered is invalid.") <> 0 Then
    MsgBox "Login failed!", vbCritical + vbOKOnly
Else
    MsgBox "Login successful!", vbInformation + vbOKOnly
End If

ie.Quit
Set ie = Nothing

End Sub
0
Comment
Question by:lgenerator
  • 2
2 Comments
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 26141057
The website looks like it should be:

fcl_userid
fcl_password

example...
ie.Document.All("fcl_userid").Value = "userid"
ie.Document.All("fcl_password").Value = "password"
0
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 2000 total points
ID: 26141551
Your example seems to fail with the revisions but this should work for you.
Option Explicit
  
Public Sub Login(ByVal szUserName As String, ByVal szPassword As String)
   
  Dim IE As Object
  Set IE = CreateObject("InternetExplorer.Application")
  IE.Visible = True
  IE.Navigate "https://secure.ftinteractivedata.com/desktop/cgi/id-menus.cgi?ref=DM"
  ' Wait for the page to load.
  Do While IE.Busy Or IE.ReadyState <> 4
    DoEvents
  Loop
  IE.Document.getElementById("fcl_userid").Value = szUserName
  IE.Document.getElementById("fcl_password").Value = szPassword
  IE.Document.getElementById("LOGIN").Submit
  ' Destroy object.
  Set IE = Nothing
  
End Sub

Open in new window

0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question