G
Guest
Trying to automate processing 80,000 data sets through 15 web pages.
Application URL creates a new IE instance in which runs first a login form
and then runs the rest of the pages in the new window.
I can connect to a running Excel instance and obtain information from the
Excel DOM. I cannot do the same with Internet Explorer. However, I can
successfully create an new IE instance and manipulate it. Using an
application that has its own VB derived scripting language I get a similar
error.
Sample VB.NET code showing ability to connect running Excel instance,
Creating an IE instance and then failing to connect to the instance is pasted
below. No try/Catch block indicates the problem is in
microsoft.visualbasic.dll. Any ideas or work arounds? VB prefered but I am
comfortable with C# and have used many other languages.
=== Output From Code as pasted ====
Excel: Renamed Sheet1
myIE.Name = Microsoft Internet Explorer
myIEDoc.url = http://www.yahoo.com/
Exception Message: Cannot create ActiveX component.
=== Output From code with no Try/Catch block ====
Excel: Renamed Sheet1
myIE.Name = Microsoft Internet Explorer
myIEDoc.url = http://www.yahoo.com/
An unhandled exception of type 'System.Exception' occurred in
microsoft.visualbasic.dll
Additional information: Cannot create ActiveX component.
=== Sample Code =====
Public Class MyExplorer
Public Shared Sub main()
' Block 1, pick up running Excel
Dim myExcel As Object
Dim myActive As Object
Dim s As String
myExcel = GetObject(, "Excel.Application")
myActive = myExcel.ActiveSheet
s = CType(myActive.Name, String)
Console.WriteLine("Excel: " + s)
' Block 2, Create Internet Explorer object and navigate
Dim myIE As New SHDocVw.InternetExplorerClass
s = ""
myIE = CType(CreateObject("InternetExplorer.Application"),
SHDocVw.InternetExplorer)
myIE.Visible = True
myIE.Navigate2("www.yahoo.com")
While myIE.ReadyState <> SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
End While
s = CType(myIE.Name, String)
Console.WriteLine("myIE.Name = " + s)
Dim myIEDoc As mshtml.IHTMLDocument2
myIEDoc = CType(myIE.Document, mshtml.IHTMLDocument2)
Console.WriteLine("myIEDoc.url = " + myIEDoc.url)
' Block 3, try to point to the running Internet Explorer
Dim myIE2 As SHDocVw.InternetExplorerClass
s = ""
Try
myIE2 = CType(GetObject(, "InternetExplorer.Application"),
SHDocVw.InternetExplorer)
myIE2.Visible = True
myIE2.Navigate2("www.microsoft.com")
Catch ex As Exception
While True
Console.WriteLine("Exception Message: " + ex.Message)
Console.WriteLine()
If ex.InnerException Is Nothing Then
Exit While
Else
ex = ex.InnerException
End If
End While
End Try
If myIE2 Is Nothing Then Exit Sub
While myIE2.ReadyState <> SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
End While
s = CType(myIE2.Name, String)
Console.WriteLine("myIE2.Name = " + s)
Dim myIEDoc2 As mshtml.IHTMLDocument2
myIEDoc2 = CType(myIE.Document, mshtml.IHTMLDocument2)
Console.WriteLine("myIEDoc2.url = " + myIEDoc2.url)
End Sub
End Class
Application URL creates a new IE instance in which runs first a login form
and then runs the rest of the pages in the new window.
I can connect to a running Excel instance and obtain information from the
Excel DOM. I cannot do the same with Internet Explorer. However, I can
successfully create an new IE instance and manipulate it. Using an
application that has its own VB derived scripting language I get a similar
error.
Sample VB.NET code showing ability to connect running Excel instance,
Creating an IE instance and then failing to connect to the instance is pasted
below. No try/Catch block indicates the problem is in
microsoft.visualbasic.dll. Any ideas or work arounds? VB prefered but I am
comfortable with C# and have used many other languages.
=== Output From Code as pasted ====
Excel: Renamed Sheet1
myIE.Name = Microsoft Internet Explorer
myIEDoc.url = http://www.yahoo.com/
Exception Message: Cannot create ActiveX component.
=== Output From code with no Try/Catch block ====
Excel: Renamed Sheet1
myIE.Name = Microsoft Internet Explorer
myIEDoc.url = http://www.yahoo.com/
An unhandled exception of type 'System.Exception' occurred in
microsoft.visualbasic.dll
Additional information: Cannot create ActiveX component.
=== Sample Code =====
Public Class MyExplorer
Public Shared Sub main()
' Block 1, pick up running Excel
Dim myExcel As Object
Dim myActive As Object
Dim s As String
myExcel = GetObject(, "Excel.Application")
myActive = myExcel.ActiveSheet
s = CType(myActive.Name, String)
Console.WriteLine("Excel: " + s)
' Block 2, Create Internet Explorer object and navigate
Dim myIE As New SHDocVw.InternetExplorerClass
s = ""
myIE = CType(CreateObject("InternetExplorer.Application"),
SHDocVw.InternetExplorer)
myIE.Visible = True
myIE.Navigate2("www.yahoo.com")
While myIE.ReadyState <> SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
End While
s = CType(myIE.Name, String)
Console.WriteLine("myIE.Name = " + s)
Dim myIEDoc As mshtml.IHTMLDocument2
myIEDoc = CType(myIE.Document, mshtml.IHTMLDocument2)
Console.WriteLine("myIEDoc.url = " + myIEDoc.url)
' Block 3, try to point to the running Internet Explorer
Dim myIE2 As SHDocVw.InternetExplorerClass
s = ""
Try
myIE2 = CType(GetObject(, "InternetExplorer.Application"),
SHDocVw.InternetExplorer)
myIE2.Visible = True
myIE2.Navigate2("www.microsoft.com")
Catch ex As Exception
While True
Console.WriteLine("Exception Message: " + ex.Message)
Console.WriteLine()
If ex.InnerException Is Nothing Then
Exit While
Else
ex = ex.InnerException
End If
End While
End Try
If myIE2 Is Nothing Then Exit Sub
While myIE2.ReadyState <> SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
End While
s = CType(myIE2.Name, String)
Console.WriteLine("myIE2.Name = " + s)
Dim myIEDoc2 As mshtml.IHTMLDocument2
myIEDoc2 = CType(myIE.Document, mshtml.IHTMLDocument2)
Console.WriteLine("myIEDoc2.url = " + myIEDoc2.url)
End Sub
End Class