0

When I close the workbook using

MyWorkbook.Close()

an empty Excel container is left behind. Something like this

but with newer version it would be gray.

How can I close this one using C# ? I am asking because I have an issue with Excel 2016, in which after

//A modal form is opened
MyWorkbook.Close();
Application.Workbooks.Open("B.xls");

B.xls is opened in another instance, leaving me with this blank and another window with B.xls. This only happens for Excel 2016 and ONLY when another form is opened before calling these. In other Excel, or without the form opened, B.xls will be opened inside this gray container.

Kenny
  • 1,902
  • 6
  • 32
  • 61
  • Have you tried app.Quit(); after closing the workbook. It will exit from the application. – sowjanya attaluri Jun 14 '16 at 10:12
  • I tried it. It does not close the gray window and it throws an _Exception HRESULT : 0x80020005 (DISP_E_TYPEMISMATCH)_ at the moment of _Workbooks.Open_. More info : Application stays the same object. after Quit() – Kenny Jun 14 '16 at 10:22
  • Are you releasing the objects properly? – sowjanya attaluri Jun 14 '16 at 10:23
  • look here had once the same problem and this SO Question helped me: http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects?rq=1 Mabey it works for you too – opelhatza Jun 14 '16 at 11:25

0 Answers0