我在用戶輸入登錄ID /密碼後正在編寫一個訪問網頁的宏。如果這些字段中的任何一個都爲空,我已經添加了代碼以退出子版本 - 但是,如何處理登錄不起作用的事件?目前,它只是將它們帶到網站登錄頁面,但我寧願讓登錄代碼循環直到登錄工作。VBA通過網站登錄處理事件
這樣做的任何方法?我不熟悉互聯網控制。
我的代碼登錄部分看起來是這樣的:
Set SupDOC = SupIE.document
With SupDOC.forms(0)
.j_username.Value = InputBox("To Login Dun & Bradstreet, Enter your D&B Username/Email: ")
If .j_username.Value = "" Then
MsgBox "No Username was entered."
Exit Sub
End If
.j_password.Value = InputBox("To Login Dun & Bradstreet, Enter your D&B Password: ")
If .j_password.Value = "" Then
MsgBox "No Password was entered."
Exit Sub
End If
.submit
End With
編輯:
有時,登錄次數,並提交正確的登錄信息後,該網站重定向到「會話超時「並且需要再次登錄。登錄後,該站點不會加載到我稍後指定的頁面。任何想法解決這個問題?
感謝,
ReadyState 4定義了什麼? (我不知道有不同的readystate狀態)。 另外,如果輸入了無效登錄名,此循環是否會執行? – AnthonyT
剛剛測試了代碼,無論我輸入什麼,它都會提示消息框 – AnthonyT
IE有4個就緒狀態,實際上它們中的每一個都表示頁面的不同加載狀態,1完全未加載,4完全加載並且你可以互動和一切。 https://msdn.microsoft.com/en-us/library/ms534361(v=vs.85).aspx – Alex