Login into a Website - vba

I have read a number of posts related to this topic, tried a number of different methods and still can't get it to work.
The macro is working for the user name and password but login not working..
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub RepsolLogin()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim form As HTMLFormElement
MyURL = "https://login.repsol.com/es/Landing/AuthnPage?returnUrl=https://www.repsol.com/es_es/"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
DoEvents
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
Do While HTMLDoc.getElementById("gigya-login-form") Is Nothing
DoEvents
Loop
Set form = HTMLDoc.getElementById("gigya-login-form")
form.all.UserName.Value = "xxx#xxx.com" 'Enter your email id here
form.all.Password.Value = "password" 'Enter your password here
form.submit
End Sub
Can anyone have a look an tell me how I must have the macro?

Related

Href VBA clicking

I've been trying many codes to click the right button and open the page to scrape the data.
I was able to have the form filled and then click on submit, but the second part I can't seem to put to work. I want it to click on the href with has the same name that I searched on the form
Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub CETIP()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = "https://www2.cetip.com.br/TitulosCRI"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.Navigate sURL
oBrowser.Visible = True
Do
Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.document
HTMLDoc.all.ddlCodigoIF.Value = "08L0002118"
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
Err_Clear:
Resume Next
End Sub

Internet scraping issue when using vba on secure site

I am trying to automate IE to pull data from a secure site how every I keep getting the same error message: "Object required"
The debugger points to the line -HTMLinput.Value = "test"
Everything before works fine. I don't know what's the problem. I have verified my ID to make sure there is no mistakes.
Sub Brows()
Dim IE As New SHDocVw.InternetExplorerMedium
Dim Policy As Object
Dim certificate As Object
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLinput As MSHTML.IHTMLElement
IE.Visible = True
IE.navigate "secure website address"
Application.Wait Now + TimeValue("00:00:02")
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Set HTMLDoc = IE.Document
Set HTMLinput = HTMLDoc.getElementById("input ID")
HTMLinput.Value = "test"
End Sub
How to log into a web site using Excel and VBA.
Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub Login_2_Website()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = "https://www.google.com/accounts/Login"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
HTMLDoc.all.Email.Value = "sample#vbadud.com"
HTMLDoc.all.passwd.Value = "*****"
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub
The program requires references to the following:
1 Microsoft Internet Controls
2. Microsoft HTML Object Library
http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html

How to use VBA to click on button in webpage after you have logged in?

I am trying to click on a button on a webpage that I login to with VBA. I have already logged in and now I want to continue the process and click on another button. Here is what I have so far
Sub MyGmail()
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://www.programworkshop.com/6.0.0.0/login/login.aspx?skin=default&lang=enu"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.Navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
HTMLDoc.all.Login.value = "something#something.com"
HTMLDoc.all.pass.value = "Password"
HTMLDoc.all.btnlogin.Click
This next line is where I hit a dead end
HTMLDoc.all.sd5.Click
Here is the code from the website
<a id="sd5" class="nodeSel" href="javascript:treeAction(strURL5)" onmouseover="window.status='Examinees';return true;" onmouseout="window.status='';return true;" onclick="javascript: d.s(5);">Examinees</a>
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
HTMLDoc.all.btnlogin.Click
While MyBrowser.Busy
DoEvents
Wend
Set HTMLDoc = MyBrowser.Document
HTMLDoc.all.sd5.Click

Excel VBA navigation of html elements

I am working on a code that uses VBA-excel to navigate to a website. Once I have logged into the website, I am not able to interact with any of the html elements within the page. I need to be able to click on some check boxes and enter a date range into a field. Here is the code that I have. It works when I open a new window but I cant get it to work within the original ie window. I would like this process to be done in one window if possible. Any feedback is greatly appreciated.
Private Sub CommandButton1_Click()
Dim yesterday As String
yesterday = Date - 1
Dim RowCount As Integer
Dim x As Integer
Dim nik As Integer
'Opens Internet Explorer
Dim Shellwins As SHDocVw.ShellWindows
Dim Shellie As SHDocVw.InternetExplorer
Set Shellwins = New SHDocVw.ShellWindows
Dim ie1 As InternetExplorer
Strurl = "father.com"
Set ie1 = New InternetExplorer
ie1.Visible = True
ie1.navigate Strurl
Do While ie1.readyState <> 4 And ie1.Busy
DoEvents
Loop
Set htmldoc = ie1.document
For Each htmlel In htmldoc.getElementsByTagName("input")
'MsgBox htmlel.Name
If htmlel.ID = "ctl00_Body_txtEmailAddress" Then
htmlel.Value = "dad#dad.com"
End If
Next
Set htmldoc = ie1.document
For Each htmlel In htmldoc.getElementsByTagName("input")
'MsgBox htmlel.Name
If htmlel.ID = "ctl00_Body_txtPassword" Then
htmlel.Value = "mom"
End If
Next
Set htmldoc = ie1.document
For Each htmlel In htmldoc.getElementsByTagName("input")
If htmlel.ID = "ctl00_Body_btnLogon" Then
htmlel.Click
End If
Next
Strurl = "url.com"
Set ie2 = New InternetExplorer
ie2.Visible = True
ie2.navigate Strurl
ie1.Quit
Do While ie2.readyState <> 4 And ie2.Busy
DoEvents
Loop
Set htmldoc = ie2.document
For Each htmlel In htmldoc.getElementsByTagName("input")
If htmlel.ID = "ctl00_Body_txtStartDate" Then
htmlel.Value = yesterday
End If
Next
Set htmldoc = ie2.document
For Each htmlel In htmldoc.getElementsByTagName("input")
If htmlel.ID = "ctl00_Body_txtEndDate" Then
htmlel.Value = yesterday
End If
Next

Click a button after automatically logging in a website

I wrote a macro so I could fill a form and access a website automatically:
Private Sub CommandButton1_Click()
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "EXAMPLE.COM"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.USER.Value = "USER1"
HTMLDoc.all.USER.FireEvent ("onchange")
HTMLDoc.all.PASS.Value = "PASS"
HTMLDoc.all.PASS.FireEvent ("onchange")
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("img")
If MyHTML_Element.getAttribute("src") = "imagesrc.gif" Then MyHTML_Element.Click: Exit For
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
After the page loads, I've been trying to get it to click another button with no luck. Do you have any idea for this?
Here is how to pause your program so that it can wait for the webpage to load. There are multiple ways of doing this but this little line of code works wonders.
Application.Wait(Now + TimeValue("0:00:10"))
Just copy and paste that into your code after the click even. This will wait for approximately 10 seconds. You can adjust the time as needed.