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:
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
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.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With