6

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.

Zombie8
  • 141
  • 2
  • 3
  • 9

1 Answers1

5

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

roufamatic
  • 18,187
  • 7
  • 57
  • 86
Tester101
  • 8,042
  • 13
  • 55
  • 78
  • I was able to get a different error when using the code snippet above. I get an "Object Creation Failed" error on that line. What would be some typical reasons this would happen for this object? – Zombie8 Jun 02 '09 at 21:05
  • The object is not created. Are you using createObject to create an internet explorer object, or just trying to use an open instance? – Tester101 Jun 03 '09 at 00:55
  • I am trying to use an existing "open" instance. – Zombie8 Jun 03 '09 at 14:46
  • I have added a few more suggestions to my answer; if those don't work I will have to investigate more roundabout solutions. – Tester101 Jun 03 '09 at 15:22