如何在Excel VBA中关闭Internet Explorer实例 [英] How to close an Internet Explorer instance inside an Excel VBA

查看:140
本文介绍了如何在Excel VBA中关闭Internet Explorer实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个Excel VBA宏,该宏将打开IE实例,从URL中提取数据,然后应该再次关闭该实例.

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.

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

我查找了该方法,它应该关闭IE实例.但是,这对我不起作用.任务管理器确认 iexplorer.exe 进程仍在运行.如果我多次运行宏,则会添加一个新实例,并且永远不会关闭它.

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.exe process is still running. If I run the macro several times a new instance is added and never closed.

如何使宏正确关闭实例?

How can I make the macro properly close the instance?

我正在使用IE 8.0和VBA 7.0.

I'm using IE 8.0 and VBA 7.0 on this.

推荐答案

由于@Sorceri在注释中正确,我创建了两个实例.以下代码可以顺利退出实例.

As @Sorceri statet correct in the comments, I have created two instances. The following Code quits the instance without problems.

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.

这篇关于如何在Excel VBA中关闭Internet Explorer实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆