Excel interop - Unable to find the Add property of the Sheets class

Doosa Srikanth 0 Reputation points
2025-03-26T11:38:07.1566667+00:00

Here’s a refined version of your query with improved grammar and clarity:


I am developing an Excel plugin in C# using Add-in Express. The plugin displays a menu item called "CreateSheet."

When the user opens Excel and selects a blank workbook, there is a default sheet named "Sheet1." If the user clicks the "CreateSheet" menu item without first selecting the default sheet, the following line of code throws a COM exception stating that the Add method is not available for the sheet object:

Excel.Worksheet xlNewWorkSheet = (Excel.Worksheet)ExcelApp.Worksheets.Add(
    Type.Missing, 
    ExcelApp.Worksheets[ExcelApp.Worksheets.Count], 
    Type.Missing, 
    Type.Missing
);

However, if the user first clicks somewhere in the default sheet ("Sheet1") and then clicks the "CreateSheet" menu item, the new sheet is added successfully without any exception.

How can I modify the code to ensure the new sheet is added reliably, even if no cell is selected in the default sheet?

Below is the exception seen.

User's image

I tried to activate the workbook, sheet1, but nothing works.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,340 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.