Delete sheet in Excel Addin using C# VSTO

Delete sheet in Excel Addin using C# VSTO

Delete():

Worksheet or Sheet object offers Delete method which allows deletion of a sheet using code within specific workbook.

Prerequisites:

  • Visual Studio 2015 or above having Microsoft Office for Developer Tool installed
  • Create Excel Addin in C# code style
  • Create a ribbon designer and put button

Code example:

private void btnDeleteSheet_Click(object sender, RibbonControlEventArgs e)
{
	//holding sheet reference
	excel.Worksheet mNeWorksheet = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet;
	//Pause alerts to run code
	Globals.ThisAddIn.Application.DisplayAlerts = false;
	//Deleting sheet
	mNeWorksheet.Delete();
	//resume alerts
	Globals.ThisAddIn.Application.DisplayAlerts = true;
}

Run the code and it will delete active sheet. Please leave your valuable comments!!!

Next : Dynamically Increase/Decrease Row Height in Excel C#

Leave a Reply

Your email address will not be published. Required fields are marked *