2016-06-09 66 views
0

我試圖讓我的宏將我登錄到網站。到目前爲止,我已經輸入了我的用戶名和密碼,但是我不知道如何讓它「點擊」按鈕。該網站是https://www.aum-inc.com/log-in和登錄按鈕不是我知道如何激活的一種。它有某種javascript。下面是我的代碼,HELP用兩行代碼寫成,我需要爲這個特定的案例進行更新。VBA宏與特定網站進行交互

Sub AUM() 
'we define the essential variables 
Dim ie As Object 
Dim pwd, username 
Dim button 

'add the "Microsoft Internet Controls" reference in your VBA Project indirectly 
Set ie = CreateObject("InternetExplorer.Application") 
With ie 
    .Visible = True 
    .Navigate ("https://www.aum-inc.com/log-in") 
    While ie.ReadyState <> 4 
     DoEvents 
    Wend 
    Set username = .document.getElementById("cphContent_C001_txtUserName") 'id of the username control (HTML Control) 
    Set pwd = .document.getElementById("cphContent_C001_txtPassword") 'id of the password control (HTML Control) 
    'HELP Set button = .document.getElementById("ctl00$cphContent$C001$btnPropLogon") 'id of the button control (HTML Control) 
    username.Value = "Account1234" 
    pwd.Value = "Password1234" 
    'HELP button.Click 
    While ie.ReadyState <> 4 
     DoEvents 
    Wend 
End With 

'insert some sort of code in VBA to find account 

Set ie = Nothing 

末次

+0

嘗試,ie.document.getElementsbyName( 「btnSubmit按鈕」)(0)。點擊。 –

回答

0

該URL不爲我工作,但是這基本上是你怎麼做。

Dim HTMLDoc As HTMLDocument 
Dim oBrowser As InternetExplorer 
Sub Login_2_Website() 

Dim oHTML_Element As IHTMLElement 
Dim sURL As String 

On Error GoTo Err_Clear 
sURL = "https://www.google.com/accounts/Login" 
Set oBrowser = New InternetExplorer 
oBrowser.Silent = True 
oBrowser.timeout = 60 
oBrowser.navigate sURL 
oBrowser.Visible = True 

Do 
' Wait till the Browser is loaded 
Loop Until oBrowser.readyState = READYSTATE_COMPLETE 

Set HTMLDoc = oBrowser.Document 

HTMLDoc.all.Email.Value = "[email protected]" 
HTMLDoc.all.passwd.Value = "*****" 

For Each oHTML_Element In HTMLDoc.getElementsByTagName("input") 
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For 
Next 

' oBrowser.Refresh ' Refresh If Needed 
Err_Clear: 
If Err <> 0 Then 
Debug.Assert Err = 0 
Err.Clear 
Resume Next 
End If 
End Sub 
  1. Microsoft Internet控制

  2. Microsoft HTML對象庫

+0

對不起...網站更正爲:https://www.aum-inc.com/log-in –