DavidLee91
06-29-2015, 11:12 PM
Hi Folks!
I am currently trying to get a VBA code to log into a website. However, I am facing an error and would really appreciate if anybody can help me! :bow:
The website I am currently trying to log in is: http://www.questnet.sg/
Below is the VBA code with Error:
Function LogInl()
Set objIEBrowser = CreateObject("InternetExplorer.Application")
objIEBrowser.Visible = True
objIEBrowser.Navigate2 "http://www.questnet.sg/"
Call FnWaitForPageLoad(objIEBrowser)
Set objPage = objIEBrowser.Document
Call FnLogin(objPage, "davidlee91", "password")
Call FnWaitForPageLoad(objIEBrowser)
End Function
'----------------------------------------------------------------------------------------------------------------------
Function FnLogin(objPage, strUserName, strPwd)
Dim Name As String
Set NameEditB = objPage.getElementByID("txtUserID")
Set PWDEditB = objPage.getElementByID("txtPassword")
NameEditB.Value = strUserName
PWDEditB.Value = strPwd
For Each objPage_Element In objPage.getElementsByTagName("input")
If objPage_Element.Type = "login" Then objPage_Element.Click:
Exit For
Next
' Set SignIn = objPage.getElementByID("signIn")
' SignIn.Click
End Function
The error message is: Run-time error '91' - Object Variable or With block variable not set.
The highlighted line in VBA is:
NameEditB.Value = strUserName
The bottom code is a part of the HTML of the website which I used to get the ElementByID.
<tr><td class="fieldlabel_bluebig">LogIn Name</td></tr>
<tr><td><input class="big_textfield" name="txtUserID" size="25" onKeyPress="javascript:enterLogin(event);" autocomplete="off"/>
<tr><td class="fieldlabel_bluebig">Password</td></tr>
<tr><td>]<input class="big_textfield" name="txtPassword" type="password" size="25" onKeyPress="javascript:enterLogin(event);" autocomplete="off"/>
function validEntry() {
if (document.forms["frmLogin"].txtUserID.value != "" && document.forms["frmLogin"].txtPassword.value != "" ){
return true ;
}else {
alert("Please key in user name and password to login!")
return false;
}
}
Guys, thanks for reading this lengthy post and I would really appreciate any help!
Thanksss!!
Regards,
David
I am currently trying to get a VBA code to log into a website. However, I am facing an error and would really appreciate if anybody can help me! :bow:
The website I am currently trying to log in is: http://www.questnet.sg/
Below is the VBA code with Error:
Function LogInl()
Set objIEBrowser = CreateObject("InternetExplorer.Application")
objIEBrowser.Visible = True
objIEBrowser.Navigate2 "http://www.questnet.sg/"
Call FnWaitForPageLoad(objIEBrowser)
Set objPage = objIEBrowser.Document
Call FnLogin(objPage, "davidlee91", "password")
Call FnWaitForPageLoad(objIEBrowser)
End Function
'----------------------------------------------------------------------------------------------------------------------
Function FnLogin(objPage, strUserName, strPwd)
Dim Name As String
Set NameEditB = objPage.getElementByID("txtUserID")
Set PWDEditB = objPage.getElementByID("txtPassword")
NameEditB.Value = strUserName
PWDEditB.Value = strPwd
For Each objPage_Element In objPage.getElementsByTagName("input")
If objPage_Element.Type = "login" Then objPage_Element.Click:
Exit For
Next
' Set SignIn = objPage.getElementByID("signIn")
' SignIn.Click
End Function
The error message is: Run-time error '91' - Object Variable or With block variable not set.
The highlighted line in VBA is:
NameEditB.Value = strUserName
The bottom code is a part of the HTML of the website which I used to get the ElementByID.
<tr><td class="fieldlabel_bluebig">LogIn Name</td></tr>
<tr><td><input class="big_textfield" name="txtUserID" size="25" onKeyPress="javascript:enterLogin(event);" autocomplete="off"/>
<tr><td class="fieldlabel_bluebig">Password</td></tr>
<tr><td>]<input class="big_textfield" name="txtPassword" type="password" size="25" onKeyPress="javascript:enterLogin(event);" autocomplete="off"/>
function validEntry() {
if (document.forms["frmLogin"].txtUserID.value != "" && document.forms["frmLogin"].txtPassword.value != "" ){
return true ;
}else {
alert("Please key in user name and password to login!")
return false;
}
}
Guys, thanks for reading this lengthy post and I would really appreciate any help!
Thanksss!!
Regards,
David