I have never used VSTO and I am finding it difficult to find a good learning aid for 2010.
My need is simple, I have a business workbook with 42 worksheets (I orignally guessed 20 but after counting found a surprising number). I want to add a ribbon (That part is easy) using VSTO to allow employees to navigate the large number of pages easily. I cannot seem to find the c# code to display a specific worksheet (Preferably by name) that I can simply add to the click event of the buttons.
Thanks
Call the Activate
method on the worksheet object (of type Microsoft.Office.Tools.Excel.Worksheet
).
You can do this by name from within your ThisWorkbook
class or via Globals.ThisWorkbook
as follows:
private Excel.Worksheet GetWorksheetByName(string name)
{
foreach (Excel.Worksheet worksheet in this.Worksheets)
{
if (worksheet.Name == name)
{
return worksheet;
}
}
throw new ArgumentException();
}
private void ActivateWorksheetByName(string name)
{
GetWorksheetByName(name).Activate();
}
Call the ActivateWorksheetByName
and pass the name of the worksheet to show.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With