Macro to Login webpage

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.

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
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,214,932
Messages
6,122,331
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top