13

Background:
I toasted my old hard drive at work and am getting a new one. With that I'll have to rebuild my machine. My manager has Windows 7 installed on him loaner laptop that I've been using while my machine is out of commision. But I've run into a problem.

We have a fair number of apps that make use of the Microsoft.Office.Interop.Excel reference. I've gotten past a few errors so far but the one I've been stuck on for the last few days (my machine actually suffered the hard drive failure after the first rebuild) and have been unnable to find a fix. I have searched for this error but can't find anyone having this problem on Windows 7, although I have tried other fixes for Windows Server 2008 to no avail.

If I can't fix this problem, I will not be able to use Windows 7 and would like to know that before I rebuild a machine only to have to wipe it and start again (for the third time).

Problem:
OS: Windows 7 Enterprise
Error Message: Exception from HRESULT: 0x800A03EC
Code:

Private m_xls As Microsoft.Office.Interop.Excel.Application
Private m_wkbk As Microsoft.Office.Interop.Excel.Workbook
Private m_wksht As Microsoft.Office.Interop.Excel.Worksheet
m_xls = New Application
m_xls.Visible = False : m_xls.DisplayAlerts = False
m_wkbk = m_xls.Workbooks.Open(Me.FilePath)
m_wksht = CType(m_wkbk.ActiveSheet, Worksheet)
'...Write some data...'
m_wkbk.SaveAs(Me.FilePath, XlFileFormat.xlWorkbookNormal, Missing.Value, Missing.Value, False, False, XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)

The error occurs on the final line.

What I've tried so far:

  1. Changing the AppPool to use the NetworkService account (it was 'ApplicationPoolIdentity' which I couldn't find in the user list in security settings). Then giving the NetworkService account full access to the appropriate folder.
  2. Giving NetworkService access to all 'Microsoft Excel Application' settings in DCOMCNFG
  3. Running this command "appcmd set config -section:asp -enableParentPaths:true" because it's the only other thing I could find
  4. Using the .SaveCopyAs() which worked but caused different errors

I just wanted to see if anyone else has run into this or not since Windows 7 is new. I can go with Server 2008 but I would like to have some solid reasoning behind it before I tell my manager it won't work.

Thank you, Jeff

Mo Patel
  • 2,321
  • 4
  • 22
  • 37
Jeff Keslinke
  • 4,278
  • 5
  • 30
  • 49
  • I would recomend using http://download.cnet.com/Filemon/3000-2094_4-10020837.html. FileMon, can tell you what is goind wring here. **SaveAs** seems like a lock or authentication issue. State if you require more info... – Adriaan Stander Dec 30 '09 at 17:44
  • Does this link help at all? http://www.made4dotnet.com/Default.aspx?tabid=141&aid=15 – shahkalpesh Dec 30 '09 at 18:03
  • @shahkalpesh: Thanks yes I did look at that earlier but it doesn't address my issue. – Jeff Keslinke Dec 30 '09 at 19:14
  • @astander: I tried an older version of filemon which crashed my machine, then tried the listed version which said to use procmon which won't work due to 'driver compatibility issues'. So I am using Process Explorer but nothing seems out of the ordinary. What info would help, I'll post it if you let me know? Thanks! – Jeff Keslinke Dec 30 '09 at 19:18
  • The example at http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.saveas.aspx uses false rather than missing for two of the parameters. Maybe try that? Might also try using the FullName property of the Workbook object for the path to save it to - http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.fullname.aspx – barrowc Dec 31 '09 at 01:36
  • @barrowc: I just tried with the false's (I'll update the post) but still get the same error. The FullName property is ReadOnly so I can't do anything with that either. But thanks anyways! – Jeff Keslinke Dec 31 '09 at 15:58
  • See [this excellent workaround](http://stackoverflow.com/questions/5327400/hresult-0x800a03ec-it-works-on-my-machine-issue-when-creating-excel-files). – Saeed Neamati May 13 '12 at 06:48

6 Answers6

18

Note: This needs to be condensed a bit as it's a compilation of all the fixes I've been making on our internal wiki but I'm not sure what subset of changes made it work so I'll include it all.

Solution:

The following changes may be a superset of how to address this problem.

-Run DCOMCNFG.exe and navigate to 'Component Services>Computers>My Computer'.
-Right click 'My Computer' and click 'Properties'.
-Open the 'COM Security' tab. Add your account for everyone of the buttons listed ('Edit Limits...' and 'Edit Default...' buttons under 'Access Permission' & 'Launch and Activate Permissions'). Give your account all access options. Click 'Apply' then 'OK'.
-While still in DCOMCNFG expand the 'My Computer' link and open the 'DCOM Config' folder.
-Right click on 'Microsoft Excel Application' and select 'Properties'.
-Under the 'Security' tab choose the 'Customize' option for 'Launch and Activation Permissions' and 'Configuration Permissions'. For both click the 'Edit...' button. Give your account access to everything.
-While still in the 'Properties' for 'Microsoft Excel Application' go to the 'Identity' tab.
-Select the 'The Interactive User' option.
-Click 'Apply' then 'OK'.
-Restart your computer.

-Try the below DCOMCNFG & ApplicationPoolIdentity change.

-Run command prompt as Administrator.
-Navigate to c:\Windows\System32\inetsrv> and run 'appcmd set config -section:asp -enableParentPaths:true'

Alternately you could use .SaveCopyAs() although this may still not address the problem and will require code changes.

DCOMCNFG For windows 7:

This error happens on 'Excel app = New Application();' calls

This link details how to fix the problem for XP/Server 2003 but can be adapted to Windows 7: http://blog.crowe.co.nz/archive/2006/03/02/589.aspx

I do not have/could not find an 'ASPNET' account. You have to check the application pool to find out what the app is running as.
To do that go into 'Computer Management>Services and Applications>Internet Information Services>Application Pools'
Right click on the appropriate AppPool and choose 'Advanced Settings'. Under 'Process Model>Identity' you can find the account it is running under. Mine was 'ApplicationPoolIdentity' which I also couldn't find so I changed it to 'Network Service' like Windows Server 2003.
Once this is set run DCOMCNFG.exe. Navigate to 'Component Services>Computers>My Computer>DCOM Config'.
Find and right-click on 'Microsoft Excel Application' and select 'Properties'. Choose the 'Security' tab. Under 'Launch and Activation Permissions' choose 'Customize' and click 'Edit'.
Then click the 'Add...' button.
Type the name of the the appropriate account, in this case 'Network Service' and click 'Check Names'. Then click 'OK'.
Back on the 'Launch and Activation Permissions' page highlight the 'Network Service' account and check the 'Local Launch' and 'Local Activation' check boxes. Then click 'OK'.

Jeff Keslinke
  • 4,278
  • 5
  • 30
  • 49
  • Anybody know if this is some quirk of Win 7, or does Jeff just have some very specific set of conditions that are leading to this? I'm struggling with a saveAs error as well. – pc1oad1etter May 18 '10 at 21:32
  • As of today this is still the only way I know of to deal with this and the rest of my team that is on Server 2008 (also Windows 6.1) is also using this to deal with it. I'd love to hear there's a better way though. – Jeff Keslinke May 19 '10 at 14:31
  • 8
    For Windows 7 64-bit, start DCOMCNFG in 32-bit mode using: DCOMCNFG -32 Otherwise, you won't see Microsoft Excel Application in the list. – Gordon Bell Dec 08 '10 at 17:32
  • Worked for me in Win7-64. I Just used Solution part. +1 – Murta Feb 27 '15 at 17:40
  • I had to use the above solution to get ABCPDF to convert Excel documents to PDF on Windows Server 2012 R2. I didn't have to do this Windows Server 2012. – BrandonG Aug 23 '15 at 17:42
4

When I was getting this error, I think I started using .SaveCopyAs instead of SaveAs. I'm not sure what other errors this is causing you, if you could elaborate there perhaps something could be figured out for that situation.

Also, one thing that you are doing is most likely causing excel.exe to remain in memory after processing a file. Here is an article that shows the proper way to use and release COM interop objects (http://support.microsoft.com/kb/317109). It is a pain, but it worked for me in allowing those resources to be released before the app closed.

Rick Mogstad
  • 817
  • 1
  • 5
  • 11
  • I should also note that I was having problems with this on Vista as well, and it seemed to be related to having a newer version of Office, rather than the version of Windows (I could re-create on XP machines as well, but not on some with older versions of the interop assemblies) – Rick Mogstad Dec 30 '09 at 20:25
  • Rick, my problem with .SaveCopyAs is fixable because I could modify the code. My problem with that is of course this is not the only place where we use this so I'd constantly have to be chaning the code so if that's the only solution then it's probably not something I'd pursue. We do know about the releasing of the excel.exe and do try to release it (although once in a while I'll go on the server and have to kill some off). So I agree while this isn't the best method it would be a major undertaking for us to change it now and that would be up to my manager whether we have the resources. – Jeff Keslinke Dec 30 '09 at 20:30
  • Sure, I just wanted to bring it up because I ran into it myself, and had to go through the trouble of figuring out what is going on. I tried for several hours to get the SaveAs() function to work without error, and never found any combination of parameters that would not error. If you can't use the SaveCopyAs(), I'm not sure what the best approach might be. Good luck! – Rick Mogstad Dec 30 '09 at 20:48
0

The answer above by Jeff Keslinke ended up working for me. You also need to look at the application pool that your App is using and make sure the identity is correct and has full access and privileges.

user1437891
  • 112
  • 1
  • 9
0

I got the same issue and found application crash errors with Exception code: 0xc0000005 in windows events. Search web and find the following solution at the linkExcel 2010 Crash, Exception code: 0xc0000005 Rename the file extension of the opened file from xlsx to zip. The solution works for my case.

Jack Liu Shurui
  • 540
  • 1
  • 5
  • 14
0

Make sure you're running the program (and EXCEL.EXE) as administrator, and the directory you're saving to doesn't have "read-only" attribute on.

Also, try passing the full file path instead of just the file name.

You could also try passing System.Reflection.Missing.Value instead of omitting the optional parameters.

Can't think of anything else right now. Hope this helps.

ShdNx

ShdNx
  • 3,172
  • 5
  • 40
  • 47
  • My account is an administrator on the machine and when I run VS it runs as administrator. I checked the excel.exe process and it was running as NetworkService which I've given access to that directory. Also Me.FilePath is the whole directory. I did try the Missing.Value but got the same error so unfortunately while those were all good ideas I'm still stuck. Thanks though! – Jeff Keslinke Dec 30 '09 at 19:11
0

Try turning on ISS . The details are mentioned here for windows 7

http://helpdeskgeek.com/windows-7/turn-on-microsoft-internet-information-services-in-windows-7/