问题描述
我使用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.
当我执行下面的代码时,我得到一个对象创建失败 - moniker语法错误。
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")
编辑:
您尝试的操作可能无法实现,请看看这个。
这篇关于重用Internet Explorer COM自动化对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!