繁体   English   中英

Internet Explorer对象Excel VBA的自动化错误未指定错误

[英]Automation Error Unspecified Error with Internet Explorer Object Excel VBA

我一直在处理一些代码,从字面上看,突然之间它突破了我。 这是我收到的错误消息:

Run-time error '-2147467259 (80004005)'
Automation error
Unspecified error

代码行特别是在实例化InternetExporer对象时,除了我没有做任何更改代码。 它刚刚停止工作。 可能是什么问题?

这发生在之前,我通过显式调用库(之前的HTMLBsaeObject的MSHTML)来纠正它,除了我在命名变量时只使用了一个Object

Public Sub ValueLineResearch()

    setUp
    Dim myFund As String

    loginN = Sheets("Logins").Range("B2").Text
    pwStr = Sheets("Logins").Range("B3").Text

    'Get the site
    iEx.Navigate "https://jump.valueline.com/login.aspx"
    iEx.Visible = True

    Call waitForIE

    'Need to login now don't we
    iEx.Document.forms("aspnetForm").Item("ctl00_ContentPlaceHolder_LoginControl_txtUserID").Value = loginN
    iEx.Document.forms("aspnetForm").Item("ctl00_ContentPlaceHolder_LoginControl_txtUserPw").Value = pwStr
    iEx.Document.forms("aspnetForm").Item("ctl00_ContentPlaceHolder_LoginControl_btnLogin").Click

    Call waitForIE
    Application.Wait DateAdd("s", 6, Now)

    iEx.Navigate "https://research.valueline.com/secure/research#sec=library"

    Call waitForIE

    For Each el1 In iEx.Document.getElementsByClassName("symbol-search textInput ui-autocomplete-input mod_search-symbols primary_symbol_search")
        el1.Value = fundToResearch
    Next

    Application.Wait DateAdd("s", 2, Now)

    iEx.Document.forms("quoteSearch").submit

    Call waitForIE
    Application.Wait DateAdd("s", 2, Now)

    iEx.Navigate "https://research.valueline.com/secure/research#list=recent&sec=company&sym=" & fundToResearch

    Call waitForIE

    'store the Doc
    Set ieDoc = iEx.Document

    'For linkItem = 0 To ieDoc.Links.Length - 1
    '    'Get the PDF
    '    If InStr(1, ieDoc.Links(linkItem).href, ".pdf", vbTextCompare) > 0 And InStr(1, ieDoc.Links(linkItem).href, "UserGuide", vbTextCompare) <= 0 Then
    '        ieDoc.Links(linkItem).Click
    '        iEx.Visible = True
    '        Exit For
    '    End If
    'Next linkItem

    Set iEx = Nothing    

End Sub

设置子是这样的:

set iEx = CreateObject("InternetExplorer.Application")
fundToResarch = LCase(InputBox("Please Enter a Fund"))

我遇到了一个类似的问题,即在一个多次调用的函数中创建一个InternetExplorer实例的“自动化错误”。 它可以正常启动,但在多次调用后会因自动化错误而崩溃。 我发现我在内存中有多个IE进程,这意味着设置objIE = Nothing不足以从内存中删除进程。 解决方案是在将objIE设置为Nothing之前调用'Quit'方法。

那是:

objIE.Quit

'Put in a brief pause

set objIE = Nothing

对于那些最终在这里遇到同样错误的人......

这也可以通过在退出并将其设置为空之后引用InternetExplorer对象中的Document对象属性引起。 请注意,这不是问题中发生的事情。 我能够使用类似于此的代码复制错误:

Dim ie As New InternetExplorer
ie.Visible = True
ie.Navigate "google.com"

ie.Quit
Set ie = Nothing

If ie.Document Is Nothing Then 'Error thrown here
    MsgBox "Can't get here"
End If

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM