Link to home
Start Free TrialLog in
Avatar of Ama Olv
Ama Olv

asked on

Debugging COM Interop HResult codes (VSTO)

I have an Excel add-in firing an HRESULT 0x800401A8 error, when calling the getter of Worksheet.Parent.

I would be glad if anyone could let me know what the error might be, but more importantly and more generally, I would like to know how I can understand these HResult codes?

I did the following but am still confused:

Read the Microsoft's documentation on the Structure of COM error Codes.
Checked this SO thread.
Tried my chances with Magnum DB.

Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

Avatar of Ama Olv
Ama Olv


Yes I did. No dual instances of Excel in my case. The error came up after a new release, and only one client is having problems (so far two users of this client are affected). Any idea what the HResult code means in that case?
Can you give some more info on the code and what it does.
Searching on Google reveals that are a number of possible causes..someone proceeded to  uninstalling reinstalling Office to get this resolved...
Have you checked these 2 users if Excel has some other problem with VBE...some extra/missing addins...other issues.
Avatar of Ama Olv


The code is meant to insert a given worksheet after the active worksheet. To do that, I have a Template.xls file stored as a Byte() resource in my .Net project. The resource is copied to a temporary file, opened by the instance of Excel from which the add-in is executed, then the wanted sheet is copied, then pasted after the active worksheet.

I have a custom function which wraps the native worksheet.copy function. My function requires an Excel.Worksheet to be provided (the sheet after which the new sheet should be copied). To retrieve the workbook the new sheet should be copied to, I do

Dim DestinationWorkbook as Excel.Workbook = After.Parent

Open in new window

I have used this wrapper for nearly a year now; it never triggered any errors. I suspect the workbook the client is working on might be special. Maybe it has broken chart sheets, pivot charts, etc. I have a meeting with them in an hour. I would like to gather as much info as possible before this "emergency" meeting. How do you usually troubleshoot the HResult errors? Do you just google the code?

The users cleaned, then ended up re-installing Office 365, and re-installing the add-in.
The whole uninstall/install is a bit suspicious...maybe it didn't got cleaned properly...
Also there is a good chance that problematic registry keys are in existance...usually these hold the "key to paradise"....a permission missing and eveything bombs out.
Avatar of Ama Olv


Permissions are also under suspicion. The update included a feature to manually update the add-in (via click once).
This is nearly a copy/paste of the code provided by Microsoft here:

Although the add-in is able to successfully check for available updates, it cannot then apply the update: Trust Not Granted Exception. I guess Excel wraps the add-in in a virtual environment which rejects the elevation of rights. Do you believe including source code which references the ClickOnce API might involve the new release to require more trust than was originally granted, hence causing all sorts of problems?
This is something i have never worked with...
Avatar of Ama Olv
Ama Olv

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial