I need to add a group header in the Excel command bar during runtime using C#, so that I can separate my Office.CommandBarButton options from the default Excel options. For example, in Excel 2013, if you go and select a row and RMB (right-mouse-button), the default command bar will be displayed with many options. You will notice that there is a header called "Paste Options:" with the standard paste icon to the left. I want to create a similar header (group) like "Paste Options:" using C#.
Btw, I use the following code sample to successfully add several Office.CommandBarButton options in Excel;
private void AddMyRowMenu()
{
Office.CommandBars commandBars = null;
Office.CommandBar commandBarRowMenu = null;
Office.CommandBarButton commandBarButtonMyOptions1;
try
{
commandBarRowMenu = commandBars["Row"];
commandBarButtonMyOptions1 = (Office.CommandBarButton)commandBarRowMenu.Controls["My Option 1"];
}
catch (ArgumentException)
{
commandBarButtonMyOptions1 = (Office.CommandBarButton)commandBarRowMenu.Controls.Add(Office.MsoControlType.msoControlButton, oMissing, oMissing, oMissing, oMissing);
commandBarButtonMyOptions1.BeginGroup = true;
commandBarButtonMyOptions1.Caption = "My Option 1";
}
commandBarButtonMyOptions1.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(commandBarButtonMyOptions1_Click);
}
I add 3 Office.CommandBarButton options using the above code and need to separate them from the default Excel RMB options for clarity.