Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (2023)

Table of Contents
1 answer Activity Videos

Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (1)

Trevor Strike 1Reputation point

2022-05-19T19:22:23.917+00:00

Hello, I have been developing an application to take a file that has been exported from the web and open it up. I have it working completely for 64 bit office, but I am running into issues trying to get it to work for 32 bit office. Here is the Error I am getting:

Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Element not found. (Exception from HRESULT: 0x8002802B (TYPE_E_ELEMENTNOTFOUND)).

I have tried all that I have found on line to do. I started with deleting all the platforms. I was not able to delete all, until I recreated one of the others that were deleted. I tried both copying from old ones and also copying from empty. These all resulted in the same error. I can open and run the full process on my machines with 64 bit office, but no one with 32 bit office can run this. When I look at the registry, non of the machines have a key for {000208D5-0000-0000-C000-000000000046}. all the keys are {00020813-0000-0000-C000-000000000046} that relate to Excel. I am unable to add to the key it is referring to.

I initially was using Microsoft Excel 16.0 Object Library and was getting a similar error but was mentioning key {00020813-0000-0000-C000-000000000046} instead. I switched to Microsoft.Office.Interop.Excel 15.0.0.0 per other discussions I had seen on the web. This is when the error switched to {000208D5-0000-0000-C000-000000000046}. I am currently at a loss of what to do to fix it so that users are able to use this on a 32 bit office machine. Thank you for your help.

C#

C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (2)

7,083 questions

Sign in to follow

0{count} votes

  1. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (3)

    Trevor Strike 1Reputation point

    2022-05-19T19:27:42.32+00:00

    Here is my code if needed part 1:
    using System;
    using System.IO;
    using System.Threading;
    using System.Windows.Forms;
    using Excel = Microsoft.Office.Interop.Excel;
    using static MoodysBasketPull.MBPMainMenu;
    using static MoodysBasketPull.APICalls;

    namespace MoodysBasketPull
    {
    class EssbaseLoadPrep
    {
    //Create variables used throughout the script and set those that need to be glaobally set
    private static readonly Excel.Application xlapp = new Excel.Application();
    private static readonly string txtPrepFileName = @\easnas.hban.us\FinanceFIT\Moodys\MoodysEssbasePrepFiles\EssbaseLoadPrep.txt;
    private static Excel.Workbook xlworkbook;
    private static Excel.Workbook xlworkbookN;
    private static Excel.Worksheet xlSheetN;
    private static Excel.Worksheet xlSheet;
    private static Excel.Range xlRange;
    private static DialogResult result;
    private static string Scenario;
    private static string Frequency;
    private static readonly string ESBLoadPath = @"\" + EssbaseServer + @"\D\inetpub\ftproot\Moodys\EssbaseProcessFiles\";
    private static string ESBLoadFileName;
    private static string ESBLoadPrepErrFileName = @\easnas.hban.us\FinanceFIT\Moodys\MoodysEssbasePrepFiles\ErrorLogs\;
    private static string msg;
    //Create stream writers for writing the data to
    private static StreamWriter EssLoad;
    private static StreamWriter EssLoadErr;

  2. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (4)

    Jack J Jun 19,821Reputation points Microsoft Vendor

    2022-05-20T06:59:21.613+00:00

    (Video) Unable to cast COM object of type 'System ComObject'

    @Trevor Strike , Welcome to Microsoft Q&A, based on my test, there is no error for me when I tested the following code for 32 bit office.

    Excel.Application application = new Excel.Application(); 

    Do you have other code to generate the error?

    I noted that you used Microsoft Excel 16.0 Object Library, but I also find another method to call the Excel.Application by using the following method:

    Please install nuget-package Microsoft.Office.Interop.Excel.

  3. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (5)

    Trevor Strike 1Reputation point

    2022-05-20T12:51:19.387+00:00

    @Jack J Jun - Thank you for your response. I will try that and let you know if that works.

  4. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (6)

    Trevor Strike 1Reputation point

    2022-05-20T12:53:45.43+00:00

    Here is the rest of the code:
    //Opens File just exported from Moody's
    public static void OpenExcelFile(string FileExcel)
    {
    //Update ProcessMsgLabel
    msg = "Opening file exported from Moody's";
    UpdateMsg(msg);
    //open Moody's file that was just exported
    xlworkbook = xlapp.Workbooks.Open(FileExcel, ReadOnly: true, IgnoreReadOnlyRecommended: true);
    }
    }
    }

    The last line is where the error comes up.

  5. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (7)

    Viorel 83,736Reputation points

    2022-05-20T13:25:52.88+00:00

    Did you check if 'Dim a As Excel.Application : Set a = New Excel.Application' etc. works as VBA macro in Excel or Word?

  6. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (8)

    Trevor Strike 1Reputation point

    2022-05-20T17:41:40.69+00:00

    @Viorel - Thank you for your response. Can you help me understand how this would help if I am using C# in Visual studio?

    Thank you

  7. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (9)

    Trevor Strike 1Reputation point

    (Video) Unable to cast COM object of type System.__ComObject to IRibbonUI. IID...

    2022-05-20T21:55:07.393+00:00

    @Jack J Jun - I have installed nuget-package Microsoft.Office.Interop.Excel and removed the reference to the extension of Microsoft.Office.Interop.Excel, and got the same error. Do I need to delete the CPU assemblies again and recreate them, or is there something else I may be missing.

    Thank you

  8. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (10)

    Jack J Jun 19,821Reputation points Microsoft Vendor

    2022-05-23T06:41:03.007+00:00

    @Trevor Strike , thanks for the feedback, I also tested the code you last posted, there is still no error for me. Then what is your current environment, I used the environment windows 10 1903.
    Also, I recommend that you could create a new app to install the nuget package to test the code instead of doing some changes in your oringinal app.

  9. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (11)

    Trevor Strike 1Reputation point

    2022-05-23T13:44:50.143+00:00

    @Jack J Jun - Thank you for continuing to look at this with me. We are using Windows 10 - 2009 as the company was told 1903 was at the end of support as of the end of May. Using Visual Studio Professional 2019 version 16.11.13. I am using .net version 4.7.2 as 4.8 crashed when I added a data source. The full application is built as a Windows form.

  10. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (12)

    Trevor Strike 1Reputation point

    2022-05-23T16:16:12.407+00:00

    @Jack J Jun - I tried creating a blank windows form, to run the process with a button to run the code for a specified file, but got the same error. The part that confuses me the most, is that the key being referred to is not in the registry, and it works great with my 64 bit. We are using Office 365 and are on version 2202 Build 16.014931.20392 for 64 bit and 32 bit office. Not sure if any of that matters, but hope this helps in trouble shooting. Is there a max file size I can open with the Interop process? Some of the files are 12+MB.
    Thank you for your help

  11. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (13)

    Jack J Jun 19,821Reputation points Microsoft Vendor

    2022-05-24T02:18:48.59+00:00

    @Trevor Strike , based on the latest reponse, it seems that I found the difference between my environment and your environment. I used office 2016 instead of office365. Maybe that you could try to install office 2016 in the virtual machine to test the code if works for you.

  12. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (14)

    Ken Tucker 5,801Reputation points

    2022-05-24T08:34:51.233+00:00

    I always advise against automating office to open an excel file. I would recommend using the open source library NPOI or openxml sdk. Both allow you to open or create excel files without needing office installed

    (Video) Unable to cast object of type 'Microsoft.SharePoint.SPListItem' to type...

    http://www.independent-software.com/introduction-to-npoi.html

    https://learn.microsoft.com/en-us/office/open-xml/open-xml-sdk

  13. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (15)

    Trevor Strike 1Reputation point

    2022-05-24T13:53:48.687+00:00

    @Jack J Jun - Thank you for your response. Correct me if I am wrong, but is not office 365 when installed on a device the same as office 2016? All my office products are a hard install on the laptop or VDI. The only difference is that whether I am using the 64 bit version or the 32 bit version. I developed the windows form application on my laptop which is a 64 bit install of office. There the process works great. The issue is when I try to run the application on the 32 bit office install using the X86 or AnyCPU version, it does not work. Are you using 32 bit office or 64 bit office? I will try to create the process on my 32 bit office install to see if that allows for the process to work there.

    If you have any other ideas, please let me know.

    Thank you for your help.

  14. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (16)

    Trevor Strike 1Reputation point

    2022-05-24T13:53:58.1+00:00

    As a side note: Basically what I am trying to do is take a file that I get which has the data headers in column A and make them the row headers instead and then save the file as a text file so that I can read the data in and create a text file that has one row for each of the data points that are in the file. There are 900+ records that I am processing with data points for every month or quarter depending on the file from year 1960 to 2052 plus two date records. If there is a better way to do this than to open the file in excel do a copy transpose paste and a few formatting changes so that I get all the digits for the numeric values(formatting as "0.#######################;(0.#####################)"), and the dates are in numeric values when one is text and the other has only the last two digits (For these I have been using the text to columns option to get them the way I want them).

  15. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (17)

    Trevor Strike 1Reputation point

    2022-05-24T13:59:31.987+00:00

    @Ken Tucker - Thank you for your advice. I will look into these.

    Basically what I am trying to do is take an excel file that I get which has the data headers in column A and make them the row headers instead and then save the file as a text file so that I can read the data in and create a text file that has one row for each of the data points that are in the file. There are 900+ records that I am processing with data points for every month or quarter depending on the file from year 1960 to 2052 plus two date records. If there is a better way to do this than to open the file in excel do a copy transpose paste and a few formatting changes so that I get all the digits for the numeric values(formatting as "0.#######################;(0.#####################)"), and the dates are in numeric values when one is text and the other has only the last two digits (For these I have been using the text to columns option to get them the way I want them).

    This being said, I am not just opening the file but I am manipulating the so that the resulting text file is as I need it for processing.

    Any additional advice is greatly appreciated.

    Thank you

  16. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (18)

    Trevor Strike 1Reputation point

    2022-05-24T18:35:44.817+00:00

    Creating the application on my 32 bit office VDI did not change the situation. I still get the error whether I use the AnyCPU configuration or the x86 configuration.

    Thank you

  17. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (19)

    Jack J Jun 19,821Reputation points Microsoft Vendor

    2022-05-25T08:27:16.503+00:00

    (Video) Sharepoint: Cannot open microsoft.office.interop.word document (2 Solutions!!)

    @Trevor Strike ,okay, I have provided many methods to try to solve your problem, but it all failed. Therefore,I will suggest that you could try other sdk to replace the interp api.

  18. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (20)

    Trevor Strike 1Reputation point

    2022-05-25T14:50:37.557+00:00

    @Jack J Jun - Thank you for your help. I have an additional question for you. Can you tell me the version of Visual studio you are using? I have a co-worker that used my code in his visual studio and the Microsoft.Office.Interop.Excel work for him, but he is using version 16.11.9 where I am using 16.11.11 and 16.11.15.

    Thank you

  19. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (21)

    Jack J Jun 19,821Reputation points Microsoft Vendor

    2022-05-26T08:18:59.767+00:00

    @Trevor Strike , please refer to the following picture:
    Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (22)

    I also used 16.11.15.

Sign in to comment

1 answer

Sort by: Newest

Most helpful Newest Oldest

  1. Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' - Microsoft Q&A (23)

    Attkinson, Chris (MOI) 0Reputation points

    2023-02-09T17:15:40.8733333+00:00

    Hello, I'm experiencing the same issue which Trevor described. What there a resolution to this issue?

    0No comments

      Sign in to comment

    Sign in to answer

    Activity

    Sign in to follow questions and users

    Videos

    1. Fix :Unable to cast object of type 'WebControls.DataControlFieldCell' to type 'System.IConvertible'.
    (Computer Programming)
    2. Migrating Defense Solutions objects from ArcGIS 9.3.1 to 10.0 gives Unable to cast COM object...
    (Roel Van de Paar)
    3. Casual chat, code, and commits
    (SDN Cast)
    4. Cannot implicitly convert type 'Microsoft.SqlServer.Dts.Pipeline.BlobColumn' to 'stri... (1 answer)
    (mlabsinfo)
    5. MVC - Fix Error - Unable to cast object of type 'System Int32' to type 'System String'
    (Vis Dotnet)
    6. A developers guide to Microsoft Identity with Christos Matskas
    (M365 Chicago)
    Top Articles
    Latest Posts
    Article information

    Author: Pres. Carey Rath

    Last Updated: 03/12/2023

    Views: 6092

    Rating: 4 / 5 (61 voted)

    Reviews: 84% of readers found this page helpful

    Author information

    Name: Pres. Carey Rath

    Birthday: 1997-03-06

    Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

    Phone: +18682428114917

    Job: National Technology Representative

    Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

    Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.