Posts
1150
Comments
891
Trackbacks
1
Excel Interop: System.Runtime.InteropServices.COMException : Microsoft Excel cannot access the file

Yes, before you say anything, Excel Interop isn’t something you should be doing, unless you have to.

Anyway, typical problem is this:  you create some C# code that uses Excel Interop to do the ugly things that you are doing, and all works fine.  Then, you try to schedule it through Windows Scheduler or SQL Server Agent or run the code from a web site in IIS, and each time you try to run it, it throws this error.

From Bob Templeton in the MSDN forums’ post here, you need to do this:

-  Create  the directory "C:\Windows\SysWOW64\config\systemprofile\Desktop " (for 64 bit Windows) or "C:\Windows\System32\config\systemprofile\Desktop " (for 32 bit Windows)

- set the permissions required on that directory (so, if using IIS, you would want to grant full permissions to the AppPool in question, with SQL Server Agent, to whatever login it is running under, etc.).

Even though I am running Windows 7 64, I had to create the directory under “System32” to get passed this error.

But really, that’s all you have to do.  Create a folder.

If you do these things and still get this error, Google for another solution.

posted on Sunday, February 06, 2011 11:49 PM Print
Comments
Gravatar
# re: Excel Interop: System.Runtime.InteropServices.COMException : Microsoft Excel cannot access the file
Andrew
10/19/2011 3:24 AM
Thanks! You saved my quitting time ;)
Gravatar
# re: Excel Interop: System.Runtime.InteropServices.COMException : Microsoft Excel cannot access the file
Paul Fuller
12/13/2013 12:40 PM
Saved my day!!! Thank you! I've been pulling my hair out for a day on this.
Gravatar
# re: Excel Interop: System.Runtime.InteropServices.COMException : Microsoft Excel cannot access the file
Falcao
6/12/2014 9:31 AM
This suggestion worked for me but as well. Thank you!
Gravatar
# re: Excel Interop: System.Runtime.InteropServices.COMException : Microsoft Excel cannot access the file
hamza
2/16/2017 10:18 AM
Thanks a lot

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 7 and 7 and type the answer here: