none
Problems faced while using MicrosoftOfficeInterop RRS feed

  • Question

  • We are developing a windows program solution in which we programmatically access the Excel functionality and control the behaviour of the *.xlsx files.

    We are using

     Visual Studio 2012 Professsional,

     Language C#

     Namespace Microsoft.Office.Interop.Excel.

     Functions being used are standard functions  like

                    ExcelApp.Workbooks.Open(…….)

           WorkBook.Save(..)

           WorkBook.Close(..) etc.

    To control behaviour of .xlsx files, We are also using events like

    BeforeClose

    BeforeSave

    BeforePrint   etc

    On few systems (operating systems Windows 7 and above with Microsoft Office 2010 and above) we are facing problems. It gives exception with exception message as  “HRESULT: 0x800AC472”.  This exception is raised randomly (i.e. if it is raised while using WorkBook.Save(..) but few seconds  before this , same file is successfully saved at same machine and same path. OR if it is raised while using ExcelApp.Workbooks.Open(…….), the same was successful just before few miliseconds.)

    We know one instance where it is expected to happen. If we are working on a machine where the office installed is a trial version (i.e. the Product Key id is not entered during installation), the above problem is known to happen. But it disappears immediately after we feed the Product key. The Program behaves perfectly.

    But on few machines where the windows is properly installed and the Office is also properly installed, the above mentioned problem is faced and we are not able to locate why the problem occurs.

    Can you guide us to locate  the problem and overcome the same?

    Monday, March 2, 2015 5:38 AM

Answers

  • Hi Mukund,

    Based on your description, on operating systems Windows7 and above with Microsoft Office 2010 and above, exception raised randomly. Could you share us whether exception raised only in on operating systems Windows7 and above with Microsoft Office 2010 and above? If so, I would assume that it might be caused by the system environment. You might need to check your project target platform and the .net framework.

    >> i.e. if it is raised while using WorkBook.Save(..) but few seconds  before this , same file is successfully saved at same machine and same path. OR if it is raised while using ExcelApp.Workbooks.Open(…….), the same was successful just before few miliseconds

    For this, it seems that your methods run crossed. Before you call the WorkBook.Save(..), I think you need to check whether all the operation were finished. You could add loop before you call the WorkBook.Save(..).
    If the exception is raised randomly on the same pc, I assume that it was caused by the special operation or the special WorkBook. I think you could try to debug them by the special operation or the special WorkBook.

    In addition, I think you could turn to the link below:

    # HRESULT 800ac472 from set operations in Excel
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/9168f9f2-e5bc-4535-8d7d-4e374ab8ff09/hresult-800ac472-from-set-operations-in-excel?forum=vsto

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 10, 2015 12:56 PM

All replies

  • Hello Mukund,

    Do you work with the Excel object model on the main thread? Do you run another threads?

    Anyway, I'd recommend releasing underlying COM objects in the code. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about that in the Systematically Releasing Objects article. It is related to Outlook, but the same principles can be applied to any other Office application.

    You may find the following forum threads helpful where the same error is described:

    Random ComException with VB.net Excel Automation

    COMException (0x800AC472) thrown periodically (and/or randomly) 

    Monday, March 2, 2015 11:58 AM
  • Thanks  Eugene Astafiev  for the suggestion.

    I have already taken care of COM release.

    Additional to that I have tried with repeating the requests with delay in loop. (1 sec delay and 10 tries)

    Both the things didn't help.

    Funny thing is that , it works on many systems but fails on few.

    Monday, March 2, 2015 12:45 PM
  • It seems you didn't notice my questions:

    Do you work with the Excel object model on the main thread? Do you run another threads?

    Monday, March 2, 2015 12:48 PM
  • Hi Mukund,

    Have you checked the difference between the Product key in the machines?

    Could you try to reinstall the Office?

    Best Regards,

    Leo

    Wednesday, March 4, 2015 7:51 AM
  • Are you using VB.NET?  This should work perfectly fine.  Please see this sample.

    http://vb.net-informations.com/excel-2007/vb.net_excel_2007_create_file.htm

    Make sure you look at ALL of the links at the bottom of that web page.  It will show you how to create an Excel file, read from Excel, write to Excel, and all kinds of other things as well.


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Friday, March 6, 2015 2:31 PM
  • Hi Mukund,

    Do you have any updates about your issue?

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, March 9, 2015 8:18 AM
  • There is only one thread running.
    Tuesday, March 10, 2015 8:18 AM
  • What type of difference I should look for ?I ensured that product keys are entered , but I didnt observe the key value for differences.

    Tuesday, March 10, 2015 8:19 AM
  • I am using C#.

    Also pl note that it is not Add In or Macro.  It is  independent Windows .exe application.

    Tuesday, March 10, 2015 8:21 AM
  • Hi Mukund,

    Based on your description, on operating systems Windows7 and above with Microsoft Office 2010 and above, exception raised randomly. Could you share us whether exception raised only in on operating systems Windows7 and above with Microsoft Office 2010 and above? If so, I would assume that it might be caused by the system environment. You might need to check your project target platform and the .net framework.

    >> i.e. if it is raised while using WorkBook.Save(..) but few seconds  before this , same file is successfully saved at same machine and same path. OR if it is raised while using ExcelApp.Workbooks.Open(…….), the same was successful just before few miliseconds

    For this, it seems that your methods run crossed. Before you call the WorkBook.Save(..), I think you need to check whether all the operation were finished. You could add loop before you call the WorkBook.Save(..).
    If the exception is raised randomly on the same pc, I assume that it was caused by the special operation or the special WorkBook. I think you could try to debug them by the special operation or the special WorkBook.

    In addition, I think you could turn to the link below:

    # HRESULT 800ac472 from set operations in Excel
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/9168f9f2-e5bc-4535-8d7d-4e374ab8ff09/hresult-800ac472-from-set-operations-in-excel?forum=vsto

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, March 10, 2015 12:56 PM