How to close an Internet Explorer instance inside an Excel VBA

烂漫一生 提交于 2021-02-18 07:32:33

问题


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

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?

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


回答1:


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.



来源:https://stackoverflow.com/questions/30624518/how-to-close-an-internet-explorer-instance-inside-an-excel-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!