PDA

View Full Version : Login Secure site



murfyang
04-11-2008, 08:28 AM
Hi, i have searched almost everywhere, google excel-programming, microsoft, excel ozgrid...:banghead: & still can't find one that can help me. Read somewhere about the web page may have frames but with my limited knowledge, i am stuck.

I would like to login to secure site with userid & password set in the vba. Attached is the file with the URL. However i have put in dummy userid & password for obvious reason.

The macro is able to bring me to the site & that's about it. It doesn't put in the userid & password into the fields.

thanks greatly for any help rendered.

murf from singapore

Norie
04-11-2008, 10:25 AM
If that's the real URL try this.

Public Sub SecureLogin()

Const strURL_c As String = "https://www.fame8.com/fame/UI/Pre_login.aspx?epyt=1"
Const strUsr_c As String = "myUserID" 'this is where i set my UserID
Const strPwd_c As String = "myPassword" 'this is where i set my password


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
'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
objIE.Visible = True

Set frm = ieDoc.frames(0).document.forms

Set tbxUsrFld = frm(0).all.Item("txtUserId")
Set tbxPwdFld = frm(0).all.Item("txtPassword")
Set btnSubmit = frm(0).all.Item("submit")

'Fill Fields
tbxUsrFld.Value = strUsr_c
tbxPwdFld.Value = strPwd_c

'submit form
frm(0).submit

'Wait for page to load
Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop

End Sub

By the way the button in the attachment doesn't work since you've not attached a macro to it.

Had to goto the VBE to play with the code.:)

murfyang
04-15-2008, 08:35 AM
Hi Norie, thanks for the code. Yeah, forgot to assign the macro.
I am able to pass the userID & password to the form inputs now but funny thing is after submit, it returns an error msg: "your session has expired..."

however, when i ' (rem) on the frm(0).submit command to skip this step & do a manual submit, there is no problem.

Had tried to put in a wait time just before the frm(0).submit but it doesn't work.

Wonder if there is any kind of check on the way the submit button is being processed by the script. It's just too alien to me.
Thanks once again for your great help.
Most willing to try out any suggestion that i can.
murf fm Singapore

Norie
04-15-2008, 09:07 AM
murf

I'm afraid I'm not going to be able to help you any further, you're on your own sorry.:)

I get a little bit wary when people ask for help to access secure websites using VBA.

Don't mind giving a few pointers, but since somebody asked me for help to access the Goldman Sachs website that's about all I'll offer.:)

PS I'm not saying that you have any evil intents - just can't be too careful.

murfyang
04-15-2008, 06:48 PM
no worries Norie, thanks, :boohoowill go in search for the solution & get back here to contribute.

regds


murf fm s'pore

murfyang
06-28-2008, 08:09 AM
Hi there, am still trying to figure out ways to solve this. Went through the script & found that the submit name is btnLogin, so did a change from

Set btnSubmit = frm(0).all.Item("submit") to
Set btnSubmit = frm(0).all.Item("btnLogin")

but how does this change the way

frm(0).submit works?

Not too sure how to paste the script here, so i have attached a zip file of the script. I beleived the code that needs I am trying to solve is located near the end of the script.
Have been reading up on this 'alien language' but not getting any where near to solving it. :banghead: Thanks again for any guide that i can get to solving this.

murfyang
06-29-2008, 05:09 PM
Hi there, i think i have solved this part of the 'mystery' for the submit command.

it's
......
......
change

'submit form
frm(0).submit

to
frm(0)("btnLogin").submit ' ("btnLogin") - this is the name of the submit command that you can find in the script.

Thanks for all the help.

murf from Singapore