vba CreateObject 随机抛出“系统关闭已被安排”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23994477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CreateObject randomly throws "A system shutdown has already been scheduled" error
提问by
I googled and SO'd, and nothing.
我用谷歌搜索了一下,什么也没有。
My job revolves around making my co-workers lives easier.
我的工作围绕着让我的同事生活更轻松。
Currently, they are using very clunky spreadsheets designed 10+ years ago.
目前,他们正在使用 10 多年前设计的非常笨重的电子表格。
In the process of migrating their tools and reports to the local intranet using PHP, i have configured a spreadsheet that downloads that persons permissions based on their Application.Username
在使用 PHP 将他们的工具和报告迁移到本地 Intranet 的过程中,我配置了一个电子表格,根据他们的 Application.Username 下载该人的权限
Then a little back and forth with the server to generate a session key, and then popinternet explorer opens up with the relevant tool they selected from a dropdown within the workbook - meaning their session and tools are then purely browser based.
然后与服务器稍微来回生成会话密钥,然后弹出Internet Explorer 使用他们从工作簿中的下拉列表中选择的相关工具打开 - 这意味着他们的会话和工具完全基于浏览器。
All works great, however randomly, sometimes, when the sub to open the internet browser is triggered a very bizarre error message appears :-
一切都很好,但随机,有时,当打开互联网浏览器的子被触发时,会出现一个非常奇怪的错误消息:-
Upon clicking Debug, the following function is shown, and you can see for yourself which line is highlighted in yellow.
单击调试后,将显示以下功能,您可以自己查看哪一行以黄色突出显示。
I can confirm i do not have any tasks at all within my taskschedule. When i end this, and run it again, chances are it runs just fine.. it is just sometimesthat this error pops up.
我可以确认我的任务计划中根本没有任何任务。当我结束它并再次运行它时,它可能运行得很好......只是有时会弹出这个错误。
Please help! Thank in advance.
请帮忙!预先感谢。
采纳答案by Blackhawk
With errors this seemingly-unrelated and intermittent, I usually opt for either a bit of delay, catching the error and retrying or both.
对于这种看似无关且断断续续的错误,我通常选择稍微延迟、捕获错误并重试或两者兼而有之。
Try the following (retry without a delay):
尝试以下操作(立即重试):
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