2014-08-27 151 views
0

一個網站,我試圖登錄使用Facebook的代碼從我的Excel,如下所示:登錄通過VBA

Sub CallChrome() 
    Set ie = CreateObject("InternetExplorer.application") 
     ie.Visible = True 
     ie.Navigate ("https://www.fb.com") 
     Do 
      If ie.ReadyState = 4 Then 
       ie.Visible = False 
       Exit Do 
      Else 
       DoEvents 
      End If 
     Loop 
     ie.Document.Forms(0).all("Username").Value = "username" 
     ie.Document.Forms(0).all("Password").Value = "password" 
     ie.Document.Forms(0).submit 

    End Sub 

然而,它顯示了一個錯誤「必選對象錯誤424」,在ie.Document.Forms(0) .. ... 儘管正在顯示登錄頁面,但我無法傳遞我的憑據。

+0

爲什麼會出現''''密碼行之後?爲什麼叫做CallChrome,然後調用InternetExplorer.application?您似乎已從[本頁]獲取代碼(http://www.mrexcel.com/forum/excel-questions/461524-visual-basic-applications-open-website-logon-username-password.html),但複製並粘貼錯誤。您是否嘗試了其他答案'用.document'' .items(「username」)=「brazenmore」'?甚至更好,你可以適應這個Facebook'Document.getElementById(「Template_GLE_Login_LoginView1_login_UserName」)。Focus'然後輸入相關信息(密碼或名稱) – RossC 2014-08-27 10:11:44

+0

是的,我試過了,同樣的錯誤! – 2014-08-27 10:13:19

+0

對於這兩種解決方案?您是否修改了'Document.getElementById(「Template_GLE_Login_LoginView1_login_UserName」)。正確地聚焦並嘗試? – RossC 2014-08-27 10:13:40

回答

1

這工作。我更換了這一點:

ie.Document.Forms(0).all("Username").Value = "username" 
    ie.Document.Forms(0).all("Password").Value = "password" 

與此:

ie.Document.all.Item("email").Value = "username" 
    ie.Document.all.Item("pass").Value = "password"