using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
private Office.CommandBar menuBar;
private Office.CommandBarPopup newMenuBar;
private Office.CommandBarButton btnRecording;
private Office.CommandBarButton btnRegistration;
private string menuTag = "Main Menu";
private string recmenuTag = "Menu Item 1";
private string regmenuTag = "Menu Item 2";
private void AddMenuBar()
{
try
{
menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(
Office.MsoControlType.msoControlPopup, missing,
missing, missing, false);
if (newMenuBar != null)
{
newMenuBar.Caption = "Main Menu Bar Item";
newMenuBar.Tag = menuTag;
btnRecording = (Office.CommandBarButton)newMenuBar.Controls.
Add(Office.MsoControlType.msoControlButton, missing,
missing, 1, true);
btnRecording.Style = Office.MsoButtonStyle.
msoButtonIconAndCaption;
btnRecording.Caption = "Menu 1";
btnRecording.FaceId = 2986;
btnRecording.Tag = recmenuTag;
btnRecording.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(
btnRecording_Click);
btnRegistration = (Office.CommandBarButton)newMenuBar.Controls.
Add(Office.MsoControlType.msoControlButton, missing,
missing, 1, true);
btnRegistration.Style = Office.MsoButtonStyle.
msoButtonIconAndCaption;
btnRegistration.Caption = "Menu 2";
btnRegistration.FaceId = 2936;
btnRegistration.Tag = regmenuTag;
btnRegistration.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(
btnRegistration_Click);
newMenuBar.Visible = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void RemoveMenubar()
{ // If the menu already exists, remove it.
try {
Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)
this.Application.ActiveExplorer().CommandBars.ActiveMenuBar.FindControl(Office.MsoControlType.msoControlPopup,
missing, menuTag, true, true);
if (foundMenu != null)
{
foundMenu.Delete(true);
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
AddMenuBar();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
RemoveMenubar();
}
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.