Hello Chris,
I have tried on my side, it workes fine.
You could try the following code:
================
using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
namespace WordAddin2
{
public partial class ThisApplication
{
private Office.CommandBar AddInMenuBar;
private Office.CommandBarButton OpenTaskPaneButton;
private void ThisApplication_Startup(object sender,
System.EventArgs e)
{
try
{
AddInMenuBar =
this.ActiveWindow.Application.CommandBars.Add(
"Amazon", missing, missing, true);
OpenTaskPaneButton = (Office.CommandBarButton)
(AddInMenuBar.Controls.Add(
Office.MsoControlType.msoControlButton,
missing, missing, missing, true));
OpenTaskPaneButton.Caption = "Search Amazon";
OpenTaskPaneButton.Style =
Microsoft.Office.Core.MsoButtonStyle.msoButtonCaption;
OpenTaskPaneButton.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(
OpenTaskPaneButton_Click);
AddInMenuBar.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source,
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void OpenTaskPaneButton_Click(Office.CommandBarButton Ctrl,
ref bool CancelDefault)
{
MessageBox.Show("The button has been clicked");
}
private void ThisApplication_Shutdown(object sender,
System.EventArgs e)
{
OpenTaskPaneButton.Delete(false);
OpenTaskPaneButton = null;
AddInMenuBar = null;
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new
System.EventHandler(ThisApplication_Startup);
this.Shutdown += new
System.EventHandler(ThisApplication_Shutdown);
}
#endregion
}
}
================
You could find the sample code in this article.
http://msdn2.microsoft.com/en-us/library/aa830702.aspx
Find the Migrating the VBA Global Template to an Add-In section.
Please let me know if this will work on your side.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)