在VBA中查找存储在IE对象中的值

时间:2016-08-13 11:07:49

标签: vba excel-vba excel

我在VBA代码中声明了一个名为IE的对象。

Set IE = CreateObject("InternetExplorer.Application")

有时用户可能会关闭链接到IE对象的浏览器。如何编写代码来查找浏览器是关闭还是打开?

如下图所示,当我在运行时将光标放在Internet Explorer对象上时,软件会显示IE。该值是否可用于确定浏览器是关闭还是打开?如果没有,还有其他方式吗?

enter image description here

2 个答案:

答案 0 :(得分:0)

使用WithEvents创建自定义类以捕获Internet Explorer事件。您需要设置对Microsoft Internet Controls的引用。

enter image description here

 building for iOS simulator, but linking in object file built for OSX, for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

答案 1 :(得分:0)

如果对象已关闭,则访问其中某些成员应该会给您一个错误。

Dim isOpen As Boolean ' False by default
On Error Resume Next
If IE.HWND > 0 Then isOpen = True
On Error Goto 0