Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > Cannot create ActiveX component?
 

Cannot create ActiveX component?

<img>http://img69.imageshack.us/img69/6182/activex.jpg</img>

I am getting the following error:

'Cannot create ActiveX component.'

The code I have got so far: 'I get the error on 'Br = GetObject(, "InternetExplorer")' this line.

Imports System
Imports System.IO
Imports System.Uri
Imports System.IO.File
Imports System.Web
Imports System.Configuration
Imports System.Text
Imports Microsoft.VisualBasic
Imports System.Data
Imports SHDocVw

Public Class Form1

    Dim Br As InternetExplorer
    Dim m As Object


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Timer1.Enabled = True
        Timer1.Interval = 1000

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        '  Try
        Br = GetObject(, "InternetExplorer")
        'Catch
        'End Try
        m = Type.Missing
        For Each ie In New ShellWindows()
            If (ie.LocationURL = "http://www.foo.com") Then
                ie.Navigate("http://www.bar.com", m, m, m, m, m)
            End If
        Next

    End Sub
End Class
<br/>
Mike Orr  Tuesday, November 10, 2009 5:21 PM
It doesn't appear that GetObject is supported, probably for security reasons. Below is another method that should work:

        Dim IEWindow, IEShell, IEShellWindows, IEApplication As Object

        IEShell = CreateObject("Shell.Application")
        IEShellWindows = IEShell.Windows

        On Error Resume Next
        For Each IEWindow In IEShellWindows
            IEApplication = IEWindow.Application 'get the application object
            Console.WriteLine(IEWindow.document.Title)
            Console.WriteLine(IEWindow.LocationURL)
        Next


Paul ~~~~ Microsoft MVP (Visual Basic)
  • Marked As Answer byMike Orr Wednesday, November 11, 2009 10:14 PM
  •  
Paul P Clement IV  Wednesday, November 11, 2009 3:37 PM
I've only seen CreateObject used with InternetExplorer, however; you would probably need to use "InternetExplorer.Application" in any event.

If you just need to navigate to a web site you could also use Process.Start.


Paul ~~~~ Microsoft MVP (Visual Basic)
Paul P Clement IV  Tuesday, November 10, 2009 6:48 PM
Thanks. I tried your suggestion of adding '.Application', but I am still getting the same error.

The purpose of the code is to retrieve the current URL.
Mike Orr  Tuesday, November 10, 2009 9:51 PM
It doesn't appear that GetObject is supported, probably for security reasons. Below is another method that should work:

        Dim IEWindow, IEShell, IEShellWindows, IEApplication As Object

        IEShell = CreateObject("Shell.Application")
        IEShellWindows = IEShell.Windows

        On Error Resume Next
        For Each IEWindow In IEShellWindows
            IEApplication = IEWindow.Application 'get the application object
            Console.WriteLine(IEWindow.document.Title)
            Console.WriteLine(IEWindow.LocationURL)
        Next


Paul ~~~~ Microsoft MVP (Visual Basic)
  • Marked As Answer byMike Orr Wednesday, November 11, 2009 10:14 PM
  •  
Paul P Clement IV  Wednesday, November 11, 2009 3:37 PM
That worked perfect.

Thanks :)
Mike Orr  Wednesday, November 11, 2009 10:15 PM

You can use google to search for other answers

Custom Search

More Threads

• cb 2008
• Interop Forms Toolkit on VS2005 and VS2008 installed side by side
• COM and vb.net IPC
• Walkthrough: Creating COM Objects with Visual Basic 2005
• Using objects on remote machine error.
• I may have gone too far (though I hope not) - receiving an interop usercontrol and dynamically adding to form - possible?
• Using Excel In Visual Studio 2005
• VB6 event hookups dissappearing after X iterations, then throwing RCW error on event disconnect
• Spell checking causes application hang
• OleDb exception in .NET Form