I'm automating the updating of embedded Excel workbooks in a Powerpoint presentation. The workbooks show charts. I'm having a problem with freqent failures caused by "Object is not connected to server (Exception from HRESULT: 0x800401FD (CO_E_OBJNOTCONNECTED))" and "RPC Server not connected" errors.
I'm using Visual Studio 2017 and C#, with Office 2016.
The specific pieces of code that seem to most often be the culprit are:
xlChart.ChartTitle.Left = (xlChart.ChartArea.Width / 2) - (xlChart.ChartTitle.Width / 2);
Excel.Range newRng = xlWorksheet.get_Range("A1", chrNewRngCol + lastRowNbr.ToString());
I'm not sure these things in and of themselves are significant. I don't know that they aren't, but there doesn't seem anything special in them. Just interactions with the Excel object.
For whatever reason, there are times when the code just loses is connection to the Excel COM object.
My question is, is there a way to re-establish it? In the things I've tried, it seems that once that RPC server is lost, I can no longer do anything with Excel. I've tried redeclaring the Excel objects, but it won't let me do that. The only thing I have so far found that works is to shut down Powerpoint and start again, in which case it may/may not fail again. But, since I can't control the error, I fear a never ending loop if I do that.
User contributions licensed under CC BY-SA 3.0