Commandbar add new menu bar

To add a new menu bar to a CommandBar in Microsoft Office (e.g., Word, Excel, PowerPoint), you can follow these steps:

Method 1: Using the Ribbon Designer

  1. Open the Visual Studio Tools for Office (VSTO) project that contains your add-in.
  2. In the Solution Explorer, double-click on the ThisAddIn.cs file to open the code-behind file.
  3. In the ThisAddIn class, add the following code to create a new menu bar:
    private void ThisAddIn_Startup(object sender, EventArgs e)
    {
     CommandBar commandBar = this.Application.ActiveWorkbook.CommandBars;
     CommandBar menuBar = commandBar.Add("My Menu Bar", MsoBarPosition.msoBarTop);
     menuBar.Visible = true;
    }

    In this example, we're creating a new menu bar named "My Menu Bar" and adding it to the top of the CommandBar.

Method 2: Using the Office UI Editor

  1. Open the Office UI Editor (available in Visual Studio 2015 and later).
  2. In the UI Editor, navigate to the "Ribbon" section.
  3. Click on the "New" button to create a new ribbon group.
  4. In the "Ribbon Group" dialog box, enter a name for your menu bar (e.g., "My Menu Bar").
  5. Set the "Type" to "Menu Bar" and the "Position" to "Top".
  6. Click "OK" to create the menu bar.

Method 3: Using XML

  1. Open the customUI.xml file in your VSTO project.
  2. Add the following XML code to create a new menu bar:
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon>
     <menuBar idMso="Menu Bar" label="My Menu Bar">
       <!-- Add menu items here -->
     </menuBar>
    </ribbon>
    </customUI>

    In this example, we're creating a new menu bar with the ID Menu Bar and the label "My Menu Bar".

Once you've added the menu bar, you can add menu items to it using the same methods.