H
HotIndigo
Guest
I am trying to open a workbook in a panel within my app - I am writing in VB .NET. When I activate the routine mnu_NewTemplate_Clickstart, when I reach the line to Start Excel Application I get an error message.
This is the essential part of the code:
Option Explicit On
Option Strict Off
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Windows.Forms.ListBox
Imports System.IO
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop
Imports Excel = Microsoft.Office.Interop.Excel
Imports Core = Microsoft.Office.Core
Imports Microsoft.Office
Imports Microsoft.Office.Tools.Ribbon
Imports RC = Microsoft.Office.Tools.Ribbon.RibbonComponent
Imports Microsoft.Office.Tools
Imports Microsoft.VisualBasic.FileIO
Imports VB = Microsoft.VisualBasic
<ComVisible(True)>
Public Class frm_Reports
Inherits Form
' Variable Definitions Here.
Private oExcel As Excel.Application = Nothing
Private oWB As Excel.Workbook
Private WithEvents oSheet As Excel.Worksheet
Private Sub mnu_NewTemplate_Click(sender As Object, _
e As EventArgs) _
Handles mnu_NewTemplate.Click
Dim XlTempPath = "C:\Tests\Temp\"
Try
If Not FileSystem.DirectoryExists(XlTempPath) Then
FileSystem.CreateDirectory(XlTempPath)
End If
Catch ex As Exception
End Try
' Code to set up Formatting Panels and Excel Container Panel.
If oExcel Is Nothing Then
Try ' Start Excel Application.
oExcel = New Excel.Application
Catch ex As Exception
End Try
' More Code here.
End If
' More code.
End Sub
End Class
When execution reaches the line oExcel = New Excel.Application I get this error message (I have included all the details):
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Reports.frm_Reports.mnu_NewTemplate_Click(Object sender, EventArgs e) in frm_Reports.vb:line 1843
InnerException:
As an alternative I tried oExcel = CType(CreateObject("Excel.Application"), Excel.Application) instead of oExcel = New Excel.Application and get this error message:
System.Exception was caught
HResult=-2146233088
Message=Cannot create ActiveX component.
Source=Microsoft.VisualBasic
StackTrace:
at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName)
at Reports.frm_Reports.mnu_NewTemplate_Click(Object sender, EventArgs e) in frm_Reports.vb:line 1844
InnerException:
I am clearly doing something wrong but all my searches have hit a blank. Is there a way to invoke Excel without hitting these errors?
HotIndigo.
Continue reading...
This is the essential part of the code:
Option Explicit On
Option Strict Off
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Windows.Forms.ListBox
Imports System.IO
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop
Imports Excel = Microsoft.Office.Interop.Excel
Imports Core = Microsoft.Office.Core
Imports Microsoft.Office
Imports Microsoft.Office.Tools.Ribbon
Imports RC = Microsoft.Office.Tools.Ribbon.RibbonComponent
Imports Microsoft.Office.Tools
Imports Microsoft.VisualBasic.FileIO
Imports VB = Microsoft.VisualBasic
<ComVisible(True)>
Public Class frm_Reports
Inherits Form
' Variable Definitions Here.
Private oExcel As Excel.Application = Nothing
Private oWB As Excel.Workbook
Private WithEvents oSheet As Excel.Worksheet
Private Sub mnu_NewTemplate_Click(sender As Object, _
e As EventArgs) _
Handles mnu_NewTemplate.Click
Dim XlTempPath = "C:\Tests\Temp\"
Try
If Not FileSystem.DirectoryExists(XlTempPath) Then
FileSystem.CreateDirectory(XlTempPath)
End If
Catch ex As Exception
End Try
' Code to set up Formatting Panels and Excel Container Panel.
If oExcel Is Nothing Then
Try ' Start Excel Application.
oExcel = New Excel.Application
Catch ex As Exception
End Try
' More Code here.
End If
' More code.
End Sub
End Class
When execution reaches the line oExcel = New Excel.Application I get this error message (I have included all the details):
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Source=mscorlib
StackTrace:
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Reports.frm_Reports.mnu_NewTemplate_Click(Object sender, EventArgs e) in frm_Reports.vb:line 1843
InnerException:
As an alternative I tried oExcel = CType(CreateObject("Excel.Application"), Excel.Application) instead of oExcel = New Excel.Application and get this error message:
System.Exception was caught
HResult=-2146233088
Message=Cannot create ActiveX component.
Source=Microsoft.VisualBasic
StackTrace:
at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName)
at Reports.frm_Reports.mnu_NewTemplate_Click(Object sender, EventArgs e) in frm_Reports.vb:line 1844
InnerException:
I am clearly doing something wrong but all my searches have hit a blank. Is there a way to invoke Excel without hitting these errors?
HotIndigo.
Continue reading...