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:
Bookmarks