使用VBA自动登录网站-获取“自动错误”“未指定错误”2147467259(80004005)

使用VBA自动登录网站-获取“自动错误”“未指定错误”2147467259(80004005),vba,Vba,在过去,我成功地使用了网站登录,但由于某种原因,我尝试自动化的最后两个网站根本不起作用。也许是因为它们是jhtml和aspx站点,我不知道。下面是aspx示例。希望与此相关的东西将与另一个相关 Sub ws8c() Dim appIEc As SHDocVw.InternetExplorerMedium ' InternetExplorer Set appIEc = New SHDocVw.InternetExplorer appIEc.navigate "http://www.benteke

在过去,我成功地使用了网站登录,但由于某种原因,我尝试自动化的最后两个网站根本不起作用。也许是因为它们是jhtml和aspx站点,我不知道。下面是aspx示例。希望与此相关的东西将与另一个相关

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

我尝试使用其他技术,如getelementsbytagnameinput,然后循环查找上面显示的ID。我必须承认,我在收集其他人的帖子,所以我可能错过了一些重要的东西。疯狂的是,我在其他地方也有类似的代码……

你应该决定你的应用程序需要什么样的安全设置完整性级别

据我所知,Internet Explorer默认使用低完整性应用程序设置

完整性设置在适用于Windows 7的用户访问控制UAC中定义,UAC定义系统信任哪些程序进行某些更改

最初声明变量appIEC时,将其声明为shDocView.InternetExplorerMedium,这表示要使用具有中等完整性设置的对象Internet Explorer

但是,在set语句中创建对象时,使用默认的低完整性设置创建它

根据我的经验,设置为可信站点的网站在中等完整性下运行,但不会在低完整性下运行。同样,受信任的网站必须在中/高完整性下运行,否则会发生自动化错误

希望这有帮助