PDA

View Full Version : Problems Logging in to a website using Excel



FRIEL
11-10-2011, 08:07 AM
morning all
I have been playing around with automating a logging into a web page
i have found the following code.

Public Sub LaunchSITE()
Const strURL_c As String ="website"
Const strUsr_c As String = email@domain.co.uk
Const strPwd_c As String = "password01"
Dim objIE As SHDocVw.InternetExplorer
Dim ieDoc As MSHTML.HTMLDocument
Dim tbxPwdFld As MSHTML.HTMLInputElement
Dim tbxUsrFld As MSHTML.HTMLInputElement
Dim btnSubmit As MSHTML.HTMLInputElement
On Error GoTo Err_Hnd
'Create Internet Explorer Object
Set objIE = New SHDocVw.InternetExplorer
'Navigate the URL
objIE.navigate strURL_c
'Wait for page to load
Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
'Get document object
Set ieDoc = objIE.document
'Get username/password fields and submit button.
Set tbxPwdFld = ieDoc.all.Item("majenta_password") 'name of the username textbox
Set tbxUsrFld = ieDoc.all.Item("majenta_username") 'name of the password textbox
Set btnSubmit = ieDoc.all.Item("submit") 'name of the submit button on the form
'Fill Fields
tbxUsrFld.Value = strUsr_c
tbxPwdFld.Value = strPwd_c
'Click submit

btnSubmit.Click

'Wait for page to load
Do Until objIE.readyState = READYSTATE_COMPLETE: Loop
Err_Hnd: '(Fail gracefully)
End Sub

but there is a problem with clicking the submit button.
i have hilighted in bold the places i suspect there to be an error but i have no idea how to fix it.

Set btnSubmit = ieDoc.all.Item("submit")
this line after running is still set to nothing whereas the other 2 befote it are to their respective textboxes.
does anyone have any ideas where i am going wrong??

CROSSPOSTED HERE: excelforum
as "Logging in to a website using Excel"

mohanvijay
11-10-2011, 09:00 AM
try this



Dim btnSubmit As MSHTML.HTMLInputButtonElement

FRIEL
11-10-2011, 09:25 AM
thanks for the help
but no joy im affraid

also the IE page doesnt show up anymore.
unless i go through step by setp. and even then its touch and go

and the button still wont press...

mdmackillop
11-10-2011, 04:59 PM
It may be a typo but this is not a string
Const strUsr_c As String = email@domain.co.uk