COMException (0x80010108 - RPC_E_DISCONNECTED) When Closing Excel.Workbook
28,824
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.
Comments
-
Steven about 4 years
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.
-
Steven about 14 yearsUnfortunately, swapping the line causing the error and the line before had no effect. The program still crashes when trying to close the sheet.
-
Todd Main about 14 yearsMan, sorry to hear this. I dealt with this issue a few times and it was always like sorcery to get it to work. The main issue here is that by the time you get to
ReportBook.Close(True)
Excel is no longer managing ReportBook - something is releasing it - hence the error. Have you tried a code step through with debug adding a watch to ReportBook? -
Steven about 14 yearsGot it! Code stepping worked. My code accidentally opened the same file twice and closed it twice (well once then crashed when closing a second time). Thanks for your help.
-
Todd Main about 14 yearsHappy to hear this. That particular error is really frustrating, so it's great that you got things worked out!
-
Vertigo over 2 yearsExactly! There were several calls to the same code which included close operation.