CreateObject随机抛出"已经安排了系统关闭"错误

时间:2014-06-02 12:22:54

标签: excel vba createobject

我用谷歌搜索了,没什么。

我的工作围绕着让我的同事过得更轻松。

目前,他们正在使用10年前设计的非常笨重的电子表格。

在使用PHP将工具和报告迁移到本地Intranet的过程中,我已经配置了一个电子表格,根据他们的Application.Username

下载该人员权限

然后在服务器上来回一点生成会话密钥,然后使用他们从工作簿中的下拉列表中选择的相关工具打开 pop Internet Explorer,这意味着他们的会话和工具然后纯粹基于浏览器。

一切都很好,无论多么随机,有时,当触发打开互联网浏览器的子时会出现一个非常奇怪的错误信息: -

单击Debug后,将显示以下功能,您可以自己查看哪条线以黄色突出显示。

我可以确认我的任务计划中根本没有任何任务。当我结束这个并再次运行它时,很可能它运行得很好......它只是有时这个错误弹出。

请帮忙!提前谢谢。

1 个答案:

答案 0 :(得分:3)

如果出现这种看似无关且间歇性的错误,我通常会选择延迟,捕获错误并重试或两者兼而有之。

尝试以下操作(无延迟重试):

Function gogogo(sessKey)
On Error GoTo ErrHandler
    reportId = Sheet2.Range("A" & (Sheet2.Range("B1").Value + 1)).Value
    Set objIE = CreateObject("InternetExplorer.Application")
    URL = "http://localinternetdomainhere/OnlineTools/" & reportId & "/access/" & sessKey
    With objIE
        .Visible = True
        .navigate URL
    End With
    ThisWorkbook.Saved = True
    ThisWorkbook.Close False
    Exit Function

ErrHandler:

    If Err.Number = &H800704A6 Then 'Put a breakpoint here to make sure this is the ACTUAL VBA error number and not the ActiveX one. You might need to check against the Err.LastDllError property
        Resume
    End If
    Err.Raise Err.Number, Err.Source, Err.Description,err.HelpFile, err.HelpContext 'Reraise the error otherwise

End Function
相关问题