Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COMException (0x80010108 - RPC_E_DISCONNECTED) When Closing Excel.Workbook

When I run the following code, I get the exception below:

''# NOTE: ExcelApp is a Private main form variable
Dim ReportBooks As Excel.Workbooks = ExcelApp.Workbooks
Dim ReportBook As Excel.Workbook = ReportBooks.Open(localFilename)
Dim ReportSheet As Excel.Worksheet = ReportBook.Sheets("Report")

''# Retreive data from sheet

ReleaseCOM(ReportSheet)
ReportBook.Close(True) ''# Error raised here
ReleaseCOM(ReportBook)
ReleaseCOM(ReportBooks)
ERROR:
COMException was unhandled
The object invoked has disconnected from its clients.
(Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

Note: All data appears to have been retreived correctly.

Please help me diagnose and overcome this error.

like image 445
Steven Avatar asked Mar 10 '10 22:03

Steven


People also ask

Why is my Microsoft Excel not closing?

Several things might potentially cause Excel not close on demand. For instance, a lack of RAM could be the culprit or perhaps having too many applications open at once, which places a heavy load on the processor in your computer. So, close all other applications first, and then attempt to close Excel again.

How do I stop Excel from closing my workbook?

Do one of the following: In the upper-right corner of the Excel window, click Close. . On the File tab, click Exit.

What happens when you close a workbook that you work with in Excel?

Closing a workbook frees up more computer memory for other activities. Closing a workbook is different from exiting, or quitting, Excel; after you close a workbook, Excel is still running. You close a workbook by using the Close command on the File tab (New!), which keeps the Excel program window open.


1 Answers

RPC_DISCONNECTED...the dreaded "The object invoked has disconnected from its clients." issue. There are a ton of causes to this, looks like you've covered the global variables issue with Excel.. Can you put the first ReleaseCOM(ReportSheet) below ReportBook(Close) and run it? Also, check out this.

like image 132
Todd Main Avatar answered Sep 28 '22 16:09

Todd Main