重用 Internet Explorer COM 自动化对象 [英] reusing Internet Explorer COM Automation Object

查看:33
本文介绍了重用 Internet Explorer COM 自动化对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 VBScript 宏来利用 InternetExplorer.Application COM 自动化对象,我正在努力重用此对象的现有实例.

I am using VBScript macros to utilize the InternetExplorer.Application COM automation object and I am struggling with reusing an existing instance of this object.

从我读到的内容来看,我应该能够使用 vbscript 中的 GetObject() 方法来获取此对象的现有实例.

From what I have read, I should be able to use the GetObject() method in vbscript to grab a hold of an existing instance of this object.

当我执行以下代码时,我收到对象创建失败 - 名字对象语法错误".

When I execute the following code I get an "Object creation failed - moniker syntax error".

我的问题真的是语法吗?

Is my issue really syntax?

我的问题是我尝试使用这个对象的方式吗?

Is my issue how I am trying to use this object?

或者我想要完成的事情无法完成?

or can what I am trying to accomplish just not be done?

代码:

Dim IEObject as object

Sub Main  
  Set IEObject =  GetObject( "InternetExplorer.Application" )

  'Set the window visable
  IEObject.Visible = True

  'Navigate to www.google.com
  IEObject.Navigate( "www.google.com" )
End Sub

此外,我运行 CreateObject() 没有问题,它会打开一个新的 Internet Explorer 窗口并导航到我想要的位置,但我不想让宏打开 Internet Explorer 的多个实例.

Also, I have no problem running the CreateObject() which opens up a new internet explorer window and navigates where i want to, but i would rather not have the macro open up multiple instances of Internet Explorer.

推荐答案

试试这个:


Set IEObject =  GetObject( ,"InternetExplorer.Application" )

*注意InternetExplorer.Application"前的逗号

试试这个:

*Notice the comma before "InternetExplorer.Application"

Try this:


Dim IE As SHDocVw.InternetExplorer

Set IE = GetObject(,"InternetExplorer.Application")

你也可以试试这个:


Dim ShellApp
Set ShellApp = CreateObject("Shell.Application")
Dim ShellWindows
Set ShellWindows = ShellApp.Windows()
Dim i
For i = 0 To ShellWindows.Count - 1
    If InStr(ShellWindows.Item(i).FullName, "iexplore.exe") <> 0 Then
        Set IEObject = ShellWindows.Item(i) 
    End If
Next
IEObject.Navigate2("http://www.google.com")


你正在尝试的可能是不可能的,看看这个.http://support.microsoft.com/kb/239470

这篇关于重用 Internet Explorer COM 自动化对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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