重复使用的Internet Explorer COM自动化对象 [英] reusing Internet Explorer COM Automation Object
问题描述
我使用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.
从我看过,我应该能够使用GetObject()方法在VBScript抓住这个对象的现有实例的保持。
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.
当我执行以下code我得到一个对象创建失败 - 绰号语法错误。
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?
code:
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
另外,我有运行的开辟了一个新的Internet Explorer窗口,并导航,我想给的CreateObject()没有问题,但我宁可不要宏观打开的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屋!