如何在 Excel VBA 中关闭 Internet Explorer 实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30624518/
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
How to close an Internet Explorer instance inside an Excel VBA
提问by Access
I'm running an Excel VBA macro which opens a IE instance, extracts data from a URL and then is supposed to close the instance again.
我正在运行一个 Excel VBA 宏,它打开一个 IE 实例,从 URL 中提取数据,然后应该再次关闭该实例。
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
' Do stuff...
' Clean up
IE.Quit
Set IE = Nothing
I looked up that method and it is supposed to close the IE instance. However that does not work for me.
The task manager confirms that the iexplorer.exeprocess is still running. If I run the macro several times a new instance is added and never closed.
我查找了该方法,它应该关闭 IE 实例。但是,这对我不起作用。任务管理器确认iexplorer.exe进程仍在运行。如果我多次运行宏,则会添加一个新实例并且永远不会关闭。
How can I make the macro properly close the instance?
如何使宏正确关闭实例?
I'm using IE 8.0 and VBA 7.0 on this.
我正在使用 IE 8.0 和 VBA 7.0。
回答by Access
As @Sorceri statet correct in the comments, I have created two instances. The following Code quits the instance without problems.
由于@Sorceri statet 在评论中是正确的,我创建了两个实例。以下代码可以毫无问题地退出实例。
Dim IE As Object
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
' Do stuff...
' Clean up
IE.Quit
Set IE = Nothing
Interesting about the above (wrong) code is, that he indeed opens 2 instances, but does not close either of them at the end.
上面(错误的)代码有趣的是,他确实打开了 2 个实例,但最后没有关闭它们中的任何一个。

