Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

reusing Internet Explorer COM Automation Object

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.

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?

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try This:


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

*Notice the comma before "InternetExplorer.Application"

EDIT: Try this:


Dim IE As SHDocVw.InternetExplorer

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

You can also try this:


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")

EDIT:
What you are trying may not be possible, take a look at this. http://support.microsoft.com/kb/239470


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...