+ Reply to Thread
Results 1 to 2 of 2

VBA to log into website to extract data

Hybrid View

andrewg10 VBA to log into website to... 11-18-2014, 06:25 PM
Marc L Re: VBA to log into website... 11-18-2014, 07:57 PM
  1. #1
    Registered User
    Join Date
    07-17-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    7

    VBA to log into website to extract data

    Hello all, I am working on a VBA code to sign into a website and extract data from that said website. The below code is what i have so far. Things that I know are incorrect: entering the username does not process. I have a feeling that it has to due the HTML code of the website and I am just not familiar with using VBA to manipulate IE at all. However, the password part works just fine. Secondly, I do not know how to trigger the "login" button. Any help would be greatly appreciated. This is all code that i have compiled from my research in understanding the subject.

    URL: https://live.barcap.com


    Sub Login()
     
    Dim appIE As Object ' InternetExplorer.Application
    Dim sURL As String
    Dim UserN As Object ' MSHTML.IHTMLElement
    Dim PW As Object ' MSHTML.IHTMLElement
    Dim Element As Object ' HTMLButtonElement
    Dim btnInput As Object ' MSHTML.HTMLInputElement
    Dim ElementCol As Object ' MSHTML.IHTMLElementCollection
    
     
    Application.ScreenUpdating = False
     
    Set appIE = CreateObject("InternetExplorer.Application")
     
    sURL = "https://live.barcap.com"
     
    With appIE
        .Navigate sURL
        ' uncomment the line below if you want to watch the code execute, or for debugging
        .Visible = True
    End With
     
    ' loop until the page finishes loading
    Do While appIE.Busy
    Loop
     
    ' enter username and password in textboxes
    Set UserN = appIE.Document.getElementsByName("user")
    If Not UserN Is Nothing Then
        ' fill in first element named "username", assumed to be the login name field
        UserN(0).Value = "xxxxx"
    End If
     
    Set PW = appIE.Document.getElementsByName("password")
    ' password
    If Not PW Is Nothing Then
        ' fill in first element named "password", assumed to be the password field
        PW(0).Value = "xxxxx"
    End If
     
    ' click 'Submit' button
    Set ElementCol = appIE.Document.getElementsByTagName("INPUT")
     
    ' loop through all 'input' elements and find the one with the value "Submit"
    For Each btnInput In ElementCol
        If btnInput.Value = "Submit" Then
            btnInput.Click
            Exit For
        End If
    Next btnInput
    
    End Sub
    HTML Code: 

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA to log into website to extract data


    Hi,

    'cause button gets an ID ("submit"), use getElementByID statement instead of a bad loop on Value !

    If you fail, post your IE version and your OS version …

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Extract data from website to an excel
    By vgothe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-27-2012, 10:51 AM
  2. Website Data Extract Problem
    By KayG in forum Excel General
    Replies: 1
    Last Post: 08-03-2012, 10:24 AM
  3. extract data from website to excel
    By asdzxc in forum Excel General
    Replies: 1
    Last Post: 05-15-2012, 03:55 AM
  4. Excel 2007 : Extract Data from Website
    By Testify in forum Excel General
    Replies: 1
    Last Post: 05-24-2011, 08:00 PM
  5. Extract and Manipulate Data from Website
    By GU42gold in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-09-2010, 07:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1