Hi SwatantraSingh-2674,
First, the type of the extended object has the same name as the type of the native Office object, but the type is defined in the Microsoft.Office.Tools.Excel or Microsoft.Office.Tools.Word namespace.
To generate a host item for an Excel worksheet, you can refer to the following code:
Microsoft.Office.Interop.Excel.Worksheet nativeWorksheet =Globals.ThisAddIn.Application.ActiveSheet;
if (nativeWorksheet != null)
{
Microsoft.Office.Tools.Excel.Worksheet vstoSheet =
Globals.Factory.GetVstoObject(nativeWorksheet);
}
More details you can refer to this document.
And the error may say it can't load a DLL.
Generally, a simple Office repair can be performed from the "Add\Remove" program to solve the problem.
If not, please try to delete invalid registry entries left by Office.
Here are some related threads:
Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'
How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass’ to interface type ‘Microsoft.Office.Interop.Excel._Application’”
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.