ASP.NET Cannot create ActiveX component
activexobject, asp.net, excel
Solution
Following migration of our ASP.NET applications to new hardware, I investigated this issue further and came up with a solution.
To resolve the issue, open "Component Services" from Administrative Tools and navigate as follows:
- Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application
- Right click Microsoft Excel Application -> Properties -> Security tab
- Click Customize for "Launch and Activation Permissions" -> Edit -> Add
- Enter "NETWORK SERVICE", click "Check Names", click OK
- Allow "Local Launch" and "Local Activation" for "NETWORK SERVICE" then click OK
- Select Customize for "Access Permissions" -> Edit -> Add
- Enter "NETWORK SERVICE", click "Check Names", click OK
- Allow "Local Access" for for "NETWORK SERVICE" then click OK
- Click OK
The ASP.NET application can now successfully create a Microsoft Excel worksheet containing the exported data.
Problem
I have a ASP.NET application that allows users to export their staff's absences each month to Microsoft Excel. The application is currently generating the following exception Exception: Cannot create ActiveX component. with the following stack trace System.Exception: Cannot create ActiveX component. at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName) at HR.ManagerSummary.ExportToExcel() in H:\Development\pagec\Visual Studio 2005\Projects\HR\ysnet2\Time\ManagerSummary.aspx.vb:line 935 at HR.ManagerSummary.btnExcel_Click(Object sender, EventArgs e) in H:\Development\pagec\Visual Studio 2005\Projects\HR\ysnet2\Time\ManagerSummary.aspx.vb:line 891 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) The code fails at the CreateObject line. ``` 'Create the Excel object Dim objXL As Object = CreateObject("Excel.Application") ' New Microsoft.Office.Interop.Excel.Application Dim objWB As Object = objXL.Workbooks.Add Dim objWS As Object = objWB.Worksheets(1) ``` I've set permission in DCOM Config for Microsoft Excel Application for the IUSR_ account but that has not resolved the issue. Any ideas would greatly be appreciated. Cheers James