Automating Excel from VB .NET

  • Thread starter Thread starter Fergus Cooney
  • Start date Start date
I found a workaround which seems to imply a bug in VB .NET.
Can others reproduce this behavior using the example in the Temporary Links
at http://www.standards.com/index.html#Temporary?

Using that example:

The following creates an Excel object and allows the code to properly
execute.

oXL = New Excel.Application() ' Works

The following does not allow the code to properly execute:

oXL = CreateObject("Excel.Application")

The following, or equivalent, allows the code to properly execute:

oXL = CreateObject("Excel.Application")'On Error Resume Next
If 1 <> 1 Then
oXL = New Excel.Application()
oXL = GetObject(, "Excel.Application")
End If

At first glance, the implication is that some library/code is not getting
loaded without including the code in the never executed If ... End If.
 
I found a workaround which seems to imply a bug in VB .NET.
Can others reproduce this behavior using the example in the Temporary Links
at http://www.standards.com/index.html#Temporary?

Using that example:

The following creates an Excel object and allows the code to properly
execute.

oXL = New Excel.Application() ' Works

The following does not allow the code to properly execute:

oXL = CreateObject("Excel.Application")

The following, or equivalent, allows the code to properly execute:

oXL = CreateObject("Excel.Application")
If 1 <> 1 Then
oXL = New Excel.Application()
oXL = GetObject(, "Excel.Application")
End If

At first glance, the implication is that some library/code is not getting
loaded without including the code in the never executed If ... End If.
 
Howard,
I use the code successfully all the time.
Not sure why you have a problem with CreateObject.

==============================
Dim objXL As Object
Dim objWBS As Object
Dim objWB As Object
Dim objWS As Object
Dim mRow As DataRow
Dim colIndex As Integer
Dim rowIndex As Integer
Dim col As DataColumn

Try
'get a running instance of Excel
objXL = GetObject(, "Excel.Application")
Catch ex As Exception
'create a new instance of Excel if there isn't one running.
objXL = CreateObject("Excel.Application")
End Try
 
Back
Top