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.

Visual Basic.NETMicrosoft Office.NET ProgrammingMicrosoft Excel

Avatar of undefined
Last Comment
Ama Olv

8/22/2022 - Mon
John Tsioumpris

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?
John Tsioumpris

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
John Tsioumpris

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 issues...like problem with VBE...some extra/missing addins...other issues.
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.
John Tsioumpris

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.
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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: https://docs.microsoft.com/en-us/visualstudio/deployment/how-to-check-for-application-updates-programmatically-using-the-clickonce-deployment-api?view=vs-2019

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?
John Tsioumpris

This is something i have never worked with...
Ama Olv

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.