2016-01-24 101 views
0

所以我有一些代碼去一個網站,然後登錄。然後我需要它去到密碼更改網址。有時,當我運行代碼,我得到以下錯誤:Excel VBA對象IE自動化所需的錯誤

Runtime Error 424: Object Required

有時調試器說,這是第一個發言的getElementById,但大多數時候,它說,問題是過去三年的getElementById聲明。代碼如下:

Dim ie As Variant 
Dim strURL As String 
Sub login() 


Set ie = New SHDocVw.InternetExplorer 
ie.Visible = True 
ie.navigate "https://minecraft.net/profile" 

While ie.Busy 
DoEvents 
Wend 

ie.document.getElementById("username").Value = "ddd" 
ie.document.getElementById("password").Value = "ddddddddddd" 

Dim htmlForm As HTMLFormElement 
Set htmlForm = ie.document.getElementById("loginForm") 
htmlForm.submit 
' ********************************************************************** 
'IE.Document.getElementById("username").Value = "ddddd" 
' IE.Document.getElementById("password").Value = "ddddd" 
' IE.Document.getElementById("signin").Click 
'********************************************************************** 
'Pause while page loads 


Application.Wait (Now + #12:00:03 AM#) 
ie.navigate "https://minecraft.net/profile/password" 

ie.document.getElementById("oldPassword").Value = "oldpass" 
ie.document.getElementById("password").Value = "enwapss" 
ie.document.getElementById("passwordConfirmation").Value = "enwapss" 


Set htmlForm = ie.document.getElementById("loginForm") 
htmlForm.submit 

End Sub 

在此先感謝!

回答

1

可能是因爲該網站在嘗試輸入值時未完全加載,網站未處於就緒狀態。

ie.navigate " https://minecraft.net/profile/password "

嘗試增加

Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop

這將循環播放,直到網頁加載相似,你已經與

Application.Wait (Now + #12:00:03 AM#)

+0

完成它在你上面的代碼的方式謝謝!像魅力一樣工作 –