View Full Version : How to login with vba
Geetha Gupta
12-14-2016, 06:18 PM
Dear all,
I am able to open a webpage - with vba but unable to login.
Sub LoadThisWebPage()
Dim oIE As SHDocVw.InternetExplorer
'Set oIE = CreateObject("InternetExplorer.Application")
Set oIE = New SHDocVw.InternetExplorer
'Make the Inter*net Explorer visible
oIE.Visible = True
oIE.Navigate2 the reqd url
'================
'Wait till the browser is busy and page is fully loaded
Do While oIE.Busy
Loop
Do While oIE.ReadyState < 4
Loop
'=================
Dim hPage As HTMLDocument 'Object 'HTMLDocument
'Dim nameEdit As HTMLDocument
Dim passWd As Object
Dim Elements As IHTMLElementCollection
Dim El As IHTMLElement
Set hPage = oIE.Document
'PROBLEM HERE ONWARDS
'Set El = hPage.getElementById("Form1")
'there is only one form
With oIE.Document.forms(0).Elements(0)
If .Name = "__VIEWSTATE" Then
.Value = "999999"
End If
End With
End Sub
Please help
Thanks in advance
Regards,
Geetha
Geetha Gupta
12-14-2016, 11:12 PM
Actually i am able to get the HTML code with
Dim oIE As SHDocVw.InternetExplorer
Set oIE = New SHDocVw.InternetExplorer
.
.
.
.
.
Set hPage = oIE.Document
Sheets("Sheet3").Cells(2, 5) = hPage.documentElement.innerHTML
But unable to identify the elements to which i can put the reqd values for logging in
Regards
Logit
12-15-2016, 12:31 PM
See if this works:
Option Explicit
Sub dataFromLeumi()
Dim myPassword As String
myPassword = "somepassword"
Dim myUserName As String
myUserName = "someusername"
Dim loginPath As String
loginPath = "https://somewebsite/Login.html"
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.navigate loginPath
Dim userName As Object
Set userName = IE.document.getattribute("uid")
userName.Item(0).Value = myUserName
Dim password As Object
password = IE.document.getelementbyid("password")
password.Item(0).Value = myPassword
IE.document.getelementbyid("enter").Click
End Sub
Geetha Gupta
12-16-2016, 05:21 AM
Yes Logit. this is what i am trying to do.
Will try your codes and be back with how it worked out
Thanks
Geetha Gupta
12-16-2016, 08:03 PM
No Logit, it is not working
i am getting stuch at the following line:
Set userName = IE.Document.getAttribute("txtCRNNo") ' stuck here
i changed the line to
IE.Document.all.Item("txtCRNNo").Value = myUserName 'not working
i changed your code a bit:
i tried declaring IE As SHDocVw.InternetExplorer
But there is no progress
Regards,
Geetha
Geetha Gupta
12-20-2016, 05:40 AM
Hi all,
tried so many ways but no success
posting my code so soeone can point out the mistake
Sub LoginToThisWebPage()
Dim ie As SHDocVw.InternetExplorer
'Set oIE = CreateObject("InternetExplorer.Application")
Set ie = New SHDocVw.InternetExplorer
'Make the Inter*net Explorer visible
ie.Visible = True
'Nav*i*gate to the www.gmail.com
'oIE.Navigate2 "www.gmail.com"
ie.Navigate2 "crn.religare.in/newcrn/CRN_Login.aspx"
'================
'Wait till the browser is busy and page is fully loaded
Do While ie.Busy
Loop
Do While ie.ReadyState < 4
Loop
'================
Dim hPage As HTMLDocument 'Object 'HTMLDocument
Dim oUserID As Object
Dim oPassWd As Object
Dim ElCol As IHTMLElementCollection
Dim El As IHTMLElement
Set hPage = ie.Document
'Sheets("Sheet3").Cells(2, 5) = hPage.documentElement.innerHTML
Set El = hPage.forms("Form1")
With El
'Debug.Print " .elements(" & e & ")"
'Debug.Print " .tagName=" & .tagName & " --- .Name=" & .Name & " --- .ID=" & .ID & " --- .Value=" & .Value
'.all.Item("_EVENTTARGET").Value = "***x"
End With
End Sub
Geetha Gupta
12-21-2016, 10:01 PM
i am using excel 2000
can this also be a reason for my not being able to do this programming?
Regards
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.