wallstudio
New Member
- Joined
- Oct 19, 2010
- Messages
- 36
I need to login to a webpage from Macro below. However, I can't locate the form and those input box. Can anyone help?
This is the URL. "https://logon.aastocks.com/mainsite/en/login.aspx?"
Thanks a lot.
This is the URL. "https://logon.aastocks.com/mainsite/en/login.aspx?"
Thanks a lot.
Code:
Sub Login_AA()
Const cURL = "https://logon.aastocks.com/mainsite/en/login.aspx?"
Const cUserID = "ID"
Const cPwd = "PW"
Dim ie As Object
Dim doc As HTMLDocument
Dim PageForm As HTMLFormElement
Dim UserIdBox As HTMLInputElement
Dim PasswordBox As HTMLInputElement
Dim FormButton As HTMLInputButtonElement
Dim Elem As IHTMLElement
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate cURL
On Error GoTo Err_Handler
Do While ie.busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
Set doc = ie.document
Debug.Print "Login page: " & ie.LocationURL
For Each Elem In doc.all
Next
Set PageForm = doc.forms("XXX")
Set UserIdBox = PageForm.elements("XXX")
UserIdBox.Value = cUserID
Set PasswordBox = PageForm.elements("XXX")
PasswordBox.Value = cPwd
PageForm.submit
Do While ie.busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
Exit_This_Sub:
Exit Sub
Err_Handler:
Resume Exit_This_Sub
End Sub