2016-10-25 94 views
0
Sub Autologin() 
    Dim IE As Object 
    Set IE = CreateObject("InternetExplorer.Application") 
    IE.Navigate "my_url" 
    IE.Document.GetElementByID("j_username").Value = "my_username"` 

错误发生在最后一行。VBA - IE自动化

Error: Run-time error '-2147417848 (80010108)': 
     Automation error, The object invoked has disconnected from its client. 

我发现这个代码能够在我的家里笔记本电脑上运行,但不是我的工作笔记本电脑。有谁知道如何解决这个问题?由于

+0

这听起来有点幼稚,但是您的工作笔记本电脑上是否安装了Internet Explorer? – RCaetano

+0

是的。该URL可以在Internet Explorer中正常打开,但不会在用户名框中输入任何内容,并且会显示错误消息。谢谢 – darrenvba

+0

这可能是因为我缺乏知识,但是您是否想要'GetElementByID'并为其分配一个值?它认为'GetElementByID'返回一个对象?它如何分配一个值?那么你是不是捕获什么被返回? – Zac

回答

0

给这个一展身手:

Dim mainDoc As HTMLDocument 
Set mainDoc = IE.document 

“这是在您添加你要访问的控件的ID名称。您可以在Internet Explorer中通过“查看 - 来源”搜索源代码来查找ID名称。

mainDoc.all("j_username").value="my_username" 

Set IE = Nothing 
Set mainDoc = Nothing 
-1

给这个一展身手:

Dim mainDoc As HTMLDocument 
Set mainDoc = IE.document 

“这是在您添加你要访问的控件的ID名称。您可以在Internet Explorer中通过“查看 - 来源”搜索源代码来查找ID名称。

mainDoc.all("j_username").value="my_username" 

Set IE = Nothing 
Set mainDoc = Nothing