views:

1668

answers:

4

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

A: 

Hi Jeff,

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
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
A: 

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
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
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
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
A: 
Jeff Keslinke
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
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
A: 

I had this problem and I lost many hours and this little simply post help me a lot.

http://support.microsoft.com/?scid=kb%3Bpt-br%3B282830&x=13&y=7

Luís Custódio