I’ve just started working on a new project for which we had to dig out one of our older libraries. We wrote it to retrieve data from MS Excel workbooks using the Office interop assemblies, and thus far it has never given us issues. A slight change this time round was that we were using our library in an ASP.NET site rather than a desktop application. As a result I was faced with two errors that we’d never seen before.
Error Message:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0×80070005 (E_ACCESSDENIED)).
Solution:
This is a COM permissions problem.
- Start > Run > dcomcnfg (or “mmc -32″ and then add the Component Services snap-in manually if you can’t find the app under step 3)
- Navigate to Component Services > Computers > My Computer > DCOM Config
- Locate the MS application giving you trouble (eg: “Microsoft Excel Application” for Excel or “Microsoft Word 97 – 2003 Document” for Word)
- Right click > Properties
- On the security tab: Select Customize under Launch and Activation Permissions and click Edit…
- Add the account under which the site is running (eg: Network Service) and assign Local Launch & Local Activation permissions
- Voila!
Error Message:
[COMException (0x800a03ec): Microsoft Excel cannot access the file '<filename>'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Solution:
This seems to be an issue with Excel/Word/etc not having access to a profile when being started via the interop route.
- Open Windows Explorer
- Depending on whether you installed a 32bit or 64bit version of office you will need to do one (or both) of the following:
- 32bit Office installation: Navigate to C:\Windows\System32\config\systemprofile
- 64bit Office installation: Navigate to C:\Windows\SysWOW64\config\systemprofile
- Verify the folder "Desktop" exists (create it if it's not there)
- Right click > Properties
- On the security tab: Add the account under which the site is running (eg: Network Service) with default permissions (Read & execute; List folder contents; Read)
- Voila!
Many thanks to the contributors of this discussion.
Error Message:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
Solution:
This is a COM permissions problem.
1. Start > Run > dcomcnfg (or "mmc -32" and then add the Component Services snap-in manually if you can't find the app under step 3)
2. Navigate to Component Services > Computers > My Computer > DCOM Config
3. Locate the MS application giving you trouble (eg: "Microsoft Excel Application" for Excel or "Microsoft Word 97 - 2003 Document" for Word)
4. Right click > Properties
5. On the security tab: Select Customize under Launch and Activation Permissions and click Edit...
6. Add the account under which the site is running (eg: Network Service) and assign Local Launch & Local Activation permissions
7. Voila!
39 comments
1 ping
Skip to comment form ↓
mauricio
January 13, 2011 at 10:32 pm (UTC 2) Link to this comment
hey Malte, great post. You made me safe lot of time. There is not a real post around here that expose a solution to this problem. Your post covers the two problems you have to deal with when working with the Microsoft.Office.Interop.
Thanks!
Malte
January 14, 2011 at 12:56 am (UTC 2) Link to this comment
Hi Mauricio, thanks for the feedback. I’m glad my post was helpful to you!
SzilardD
April 2, 2011 at 10:57 am (UTC 2) Link to this comment
This is really helpful. Thanks so much.
etatmirtna
July 7, 2011 at 3:44 am (UTC 2) Link to this comment
Unfortunately now my Excel will not start without errors about OLE happening. Trying to uninstall then reinstall…otherwise at least I was able to connect to the file and make a change in it
Malte
July 14, 2011 at 12:10 pm (UTC 2) Link to this comment
Hi etatmirtna, I’m afraid I haven’t experienced that problem before. Please let us know if you manage to fix it – and how!
Jynx
July 14, 2011 at 11:08 am (UTC 2) Link to this comment
Good concise article Malte.
Hope you don’t mind but I have linked this article from my blog http://jynxeddevelopment.blogspot.com/2011/07/microsoft-office-interop-tricks-and.html – it took me ages to work this out from other threads and posts so I thought I would create my own, then I found yours, wish I had found it first!
Thanks.
Malte
July 14, 2011 at 12:31 pm (UTC 2) Link to this comment
Hi Jynx, not at all. Thanks for the feedback. It took me a while to piece all this together too, so I thought I might as well make it a little easier for folks. An issue that’s encountered often – judging by the popularity of this page alone. Looks like I need to add ‘windows service’ to the keywords.. I thought it was specific to IIS7.
By the way, congrats on a great first blog post!
Rajesh Hatwal
August 4, 2011 at 6:30 am (UTC 2) Link to this comment
Thnaks a lot, It really works. I tried the second solution in windows 7 32 bit and windows server 2008 32 bit
Kalle
August 10, 2011 at 7:40 am (UTC 2) Link to this comment
You are a saviour… I have spent a couple of hours ripping my hair out over this and you solved it for me!
Malte
August 10, 2011 at 7:42 pm (UTC 2) Link to this comment
Great! Hope you still have some hair..
Chinwendu P. Ochonma
September 24, 2011 at 3:27 pm (UTC 2) Link to this comment
I have applied the first Solution to the COM error in my webservice application, but i still keep having the same error
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0×80070005 (E_ACCESSDENIED))
Malte
September 25, 2011 at 12:24 pm (UTC 2) Link to this comment
Hi Chinwendu, the only thing I can think of is that perhaps you added permissions for the wrong account. You can check which account the site is running under by selecting the site in IIS Manager and then clicking Basic Settings in the actions pane. This will tell you which application pool the site is using. Now go to Application Pools and check the identity of that application pool. The identity is the account for which you need to add the permissions. If the identity is “ApplicationPoolIdentity”, check here for a good explanation of which account that actually maps to.
Jesse HUnter
February 9, 2012 at 4:45 am (UTC 2) Link to this comment
The above step didn’t solve the access issue for me either. I had to also customize the Access Permissions and grant Local Access to my process.
CBH
November 4, 2011 at 11:07 am (UTC 2) Link to this comment
Hello, I had followed your step, but I still got the same error. My Server use Window Server 2008 R2 (x64) OS and I had installed the Microsoft Office 2007 in the it.
Any other solutions.
Thanks you in advance.
Malte
November 4, 2011 at 8:16 pm (UTC 2) Link to this comment
Hi there,
which error is it exactly that you’re getting? You might want to try the mmc -32 way if you’re getting the ‘COM class factory’ error and Office is 32-bit. Also check out the discussion I linked to at the end of the post.
Chi
November 17, 2011 at 4:51 pm (UTC 2) Link to this comment
Hi Malte,
I followed the instruction on your post. It partial resolves my web service the 2 errors that you mentioned above. However, my web service still have problem with launching the Excel and cannot run the Macro. I wonder if you have any ideas why Excel does not launch.
I have my web service run on iis 7.5, windows 7 64 bit. .NET framework 3.5, Microsoft office 2010 (32 bit)
These are the items that I did:
1. follow the above instructions to use DCOM to grant the NETWORK_SERVICE account permission to activate, access and launch the Excel locally.
2. create Desktop folder under C:\Windows\SysWOW64\config\systemprofile
folder
3. Grant NETWORK_SERVICE account full permission to the folder tree: : C:\Windows\SysWOW64\config\systemprofile
When I ran my web service in the debug mode, the application go pass Excel worksheet statement excel.open() but I donot see the Excel application launch at all ( i have set the Excel visible to true) and it stuck at the Run Macro statement. I looked at the task manager, I do not see any Excel instance being create at all. I am not sure what causes the problem. (Note: the application run fine is the IDE with integrated web server)
Below is my sample code:
Imports Microsoft.Office.Interop.Excel
Dim oExcel As Application = New Application
Dim oBook As Workbook
Dim oBooks As Workbooks
Try
‘Start Excel and open the workbook.
‘oExcel = CreateObject(“Excel.Application”)
oExcel.Visible = True
oExcel.DisplayAlerts() = True
oBooks = oExcel.Workbooks
oBook = oBooks.Open(“c:\temp\book1.xls”)
‘Run the macros.
oExcel.Run(“DoKbTest”)
‘Clean-up: Close the workbook and quit Excel.
oBook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)
oBook = Nothing
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks)
oBooks = Nothing
oExcel.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oExcel)
oExcel = Nothing
GC.Collect()
returnStr = “execute sucessfully”
Catch ex As Exception
oExcel.Quit()
oExcel = Nothing
GC.Collect()
returnStr = “Exception occurred: ” & ex.Message
‘System.Console.WriteLine(“Error occurred ” & ex.Message)
End Try
Return returnStr
I ‘d appreciate all your help.
Chi
Malte
November 17, 2011 at 7:36 pm (UTC 2) Link to this comment
Hi Chi,
Are you sure that the macro works? Can you run it manually?
Perhaps you could try doing something else to test the interop – like creating or editing a wokbook. If that works at least you’ve narrowed it down to the macro statement.
As for Excel not appearing in task manager, that is very odd (make sure to click ‘Show processes from all users’). And you’re not getting any exceptions? Perhaps check the event log for any messages that may have been missed.
chi
November 17, 2011 at 8:44 pm (UTC 2) Link to this comment
Hi Malte,
yes, the Macro is working. It is simple macro that I display the simple message to confirm the macro function is executed. I am able to run my web service inside the IDE with integrated web server without problem. The application launch the Excel application, open the workbook, run the macro to display the testing message and close the Excel instance correctly.
when running the web service from IIS server, the application is hang when try to executing the run statement to run the macro function. The browser status symbol keeps spinning to wait for response from web service, There is no error exceptions. I looked at the event viewer (sinde the browser is not response or return any message) but I do not see any related error. I could not find any strange thing happen inside the web logs neither.
I will follow your suggestion to see if it works with create or edit the worksheet. I will update after the test.
Thanks
Chi
chi
November 23, 2011 at 10:46 pm (UTC 2) Link to this comment
Hi Malte,
I tried to read the Excel spreadsheet but I can’t read the file at all. The web page just hang; no repsonse. I looked at the task manager; there is an Excel application run under application pool account which I granted the permission on Desktop folder and Dcom. I am not getting any error exception at all. The web page just keep waitng for reponse. I found nothing on the event log. The Macro statement and the loop through spreadsheet code is working fine within the visual Studio 2010.
Thanks
Chi
Malte
November 28, 2011 at 11:55 pm (UTC 2) Link to this comment
Hi Chi, that is very odd. Unfortunately there are many things which could be a factor, including the application pool identity, IIS settings, permissions, Excel version etc.
As it works for you when you run it through VS I would suggest you look for the problem with IIS and the app. pool. Another thing I would try is to use something like procmon to find out what exactly that Excel process is getting up to and perhaps even see an exception that had not been surfaced before.
Sergio
December 1, 2011 at 9:43 pm (UTC 2) Link to this comment
Hi Malte.
Great article. I have IIS7 windows 7 x64 and Office 2007. My app works under vstudio development server but not on IIS.
I’ve got first error, but i can’t complete your procedure, case I don’t see Excel under DCOM Config node.
Malte
December 2, 2011 at 12:30 am (UTC 2) Link to this comment
Hi Sergio, have you tried with mmc -32 under step 1?
Sergio
December 2, 2011 at 2:40 am (UTC 2) Link to this comment
Yes. mmc -32 shows empty console
Malte
December 2, 2011 at 11:14 am (UTC 2) Link to this comment
After mmc -32 you need to go to File > Add/Remove Snap-in and add the Component Services snap-in to the management console.
chi
December 1, 2011 at 11:26 pm (UTC 2) Link to this comment
Hi Malte,
Right now, i have problem with the Excel now. I received “cannot use object linking or Embedding” error whenever I click on the Excel spreadsheet.
I will try your suggest to use process monitor.
Thanks for response.
Chi
Phil
January 3, 2012 at 5:23 pm (UTC 2) Link to this comment
Finally someone who’s posted a proper fix for this issue.
I don’t normally bother commenting but this has really helped me.
i would like to add something though. Microsoft Excel Application never seems to be in the list in DCOM config for me. There are two CLSIDs at the bottom of the list that begin 00 (never the same as the error message says) which if you click properties show a path pointing to office.14. Add network service as above for both of these and it worked for me.
Thanks again.
Ted Porter
April 25, 2012 at 9:00 pm (UTC 2) Link to this comment
This artical is a life save.
I have just ported a mixed Classic ASP and ASP.NET web application from Server 2003 32-bit to Server 2008 R2 and nearly had to go back to the old platform.
Thank you so very much for publishing it and making it so easy to follow.
Cris
May 12, 2012 at 9:19 pm (UTC 2) Link to this comment
Hello,
I was wondering if anyone here knew how to display an Excel file through a website with “using Excel = Microsoft.Office.Interop.Excel;”.
I have been able to populate & open the excel file for the user when I press CNTRL-F5, so that I could run it locally, but when I run that same code on my ii7 server for other people to login & use it, I cannot get the excel sheets to open up or populate.
I’ve been searching, but, seeing this post, I really hope someone can help to shorten the time I spend searching for a solution.
I get no error message. It just doesn’t open the excel files or do anything when I click the button to open up the excel files. But, it works locally.
Thank you so much in advance..
Cris
luis
June 4, 2012 at 9:03 pm (UTC 2) Link to this comment
thank you very much….
elsewhere only focused advice to the dcom configuration …
the problem of the windows folder no one knew about this …
greetings master
PD. sorry my english
Soniya
June 6, 2012 at 10:14 am (UTC 2) Link to this comment
Awesome post! Thanks a lot ..
Kiran
June 8, 2012 at 12:09 pm (UTC 2) Link to this comment
Hi Malte,
Great artical.. very appreciable..
Fighting for the above second issue since couple of hours.
Your solutions saves my time.
Nathaniel
June 11, 2012 at 5:13 pm (UTC 2) Link to this comment
Great Article,
I am using this for a simple excel import/export, it works perfectly but after a few hours of this running.
Any webpage using this feature will respond with _blank page, debugging returns no error.
It appears to be a timeout issue with dcom, has anyone had this happen to them?
It happens that if i log into the server and open excel manually this stops for a few more hours, then reappears.
Francisco Villegas
July 19, 2012 at 5:42 pm (UTC 2) Link to this comment
Hola,
Muchas gracias por la ayuda, he estado 2 dias pegado en varios foros, pero aqui encontre la solución!!
Gracias!!
Saludos,
Francisco
ram
August 28, 2012 at 2:55 am (UTC 2) Link to this comment
Great post. The both solutions worked for me. I have Windows web server 2008 32 bit version. ASP.net 1.1 and MS Office 2003. once i applied the above solutions i am able to read the excel file and insert the data into SQL server
TComer
October 10, 2012 at 3:47 am (UTC 2) Link to this comment
Great info! I found that my application was running under the default “ApplicationPoolIdentity” in IIS7. Changing this to the Network Service account after configuring the application in mmc resolved the issue for me. Thanks again.
Vinit
January 13, 2013 at 8:50 pm (UTC 2) Link to this comment
It works… Many Thanks!
mat
February 26, 2013 at 10:19 am (UTC 2) Link to this comment
Been working on this crap for 4 days straight (even completley destroyed a OS) and this worked perfectly.
Cheers
anduin
May 6, 2013 at 7:07 pm (UTC 2) Link to this comment
In IIS 7.5 you need to change the app pool identity to NETWORK SERVICE from APPPOOLIDENTITY then give permissions to the desktop folder and run all the other dcom permissions through that.
4 weeks, and a fractured skull later.
yogesh
May 7, 2013 at 10:17 am (UTC 2) Link to this comment
I have my web service run on IIS 7.5, windows 7 64 bit. .NET framework 4.0, Microsoft office 2010 (32 bit).
I have done changes according to the solution 1.
I changed the settings shown above and given permission to IIS_IUSRS user, but changes are not persisted.
When I again open the properties/security tab..changes were lost.
Excel 2010 automation with Asp.Net, on top of a Windows Server 2008 R2 64 with IIS 7.5 « thewayofcode
May 12, 2012 at 3:47 pm (UTC 2) Link to this comment
[...] problems 1 and 2 have been successfully addressed in the past, see for example http://www.bloing.net/2011/01/how-to-make-iis7-play-nice-with-office-interop/ or [...]