2014-01-09 56 views
0


我已經成功地使用網站登錄過去,但由於某種原因,我試圖自動化的最後兩個網站沒有一切工作。也許是因爲他們是jhtml和aspx網站,我不知道。下面是aspx的例子。希望對此有效的將與另一方合作。自動登錄網站使用VBA - 獲取「自動化錯誤」「未指定的錯誤」2147467259(80004005)

Sub ws8c() 

Dim appIEc As SHDocVw.InternetExplorerMedium ' InternetExplorer 
Set appIEc = New SHDocVw.InternetExplorer 
appIEc.navigate "http://www.bentekenergy.com/Login.aspx" 

While appIEc.Busy 
    DoEvents 
Wend 

' I get the error here! if I comment this out I get the error here too 
appIEc.document.getElementById("ctl00_MasterMainContent_LoginCtrl_Username").Value = "MyUserName" 

'if I comment the above line out I get the error here too 
appIEc.document.getElementById("ctl00_MasterMainContent_LoginCtrl_Password").Value = "MyPW" 

' This part doesn't work either... 
Set ElementCol = appIEc.document.getElementsByTagName("a") 
For Each btna In ElementCol 
If btna.ID = "ctl00_MasterMainContent_LoginCtrl_btnSignIn" Then 
btna.Click 
Exit For 
End If 
Next btna 

While appIEc.Busy 
    DoEvents 
Wend 

appIEc.navigate "http://www.bentekenergy.com/Benport/HubFlowMaps.aspx?sg=6", CLng(2048) 

Set appIEc = Nothing 

End Sub 

我試圖使用其它技術像getElemengByTagName(「輸入」),然後通過循環並尋找該ID已如上所示。我不得不承認,我有點像其他人的帖子一樣,所以我可能會錯過一些重要的東西。什麼是瘋狂的,我有非常相似的代碼在其他地方工作....

回答

0

你應該決定你的應用程序需要什麼安全設置(完整性級別)。

從我的理解來看,默認情況下,Internet Explorer使用低完整性應用程序設置。

完整性設置在Windows 7的用戶訪問控制(UAC)中定義,UAC定義系統信任哪些程序進行某些更改。

當您最初聲明變量appIEC時,您將其聲明爲shDocView.InternetExplorerMedium,它表示您希望使用具有中等完整性設置的對象(Internet Explorer)。

但是,當您在set語句中創建對象時,使用默認的Low Integrity設置創建了它。

根據我的經驗,設置爲可信站點的網站以中等完整性運行,但不會在低完整性下運行。同樣,受信任的網站必須在「中/高完整性」下運行,否則會發生自動化錯誤。

希望這有助於!

相關問題