Hi
I'm trying to write application-level add-in for Word 2003.
The plugin adds a button on a new commandbar - clicking the button saves active document and then performs some additional actions. When I launch Word 2003 and then click my commandbar button everything works fine.
However if I launch Word 2003, open a new Word window by clicking toolbar button "New document" on a "Standard" toolbar and then click my commandbar button it turns out that no action is performed. It seems that my toolbar button on a new opened window has no "onclick" event handler assigned. Do you have any idea how to solve the problem ?
My add-in code is based on the code below:
private Office.CommandBar commandBar;
private Office.CommandBarButton docSaveButton;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// prepare toolbar:
try
{
commandBar = Application.CommandBars["MY_TOOLBAR"];
}
catch (ArgumentException)
{
//...
}
if (commandBar == null)
{
commandBar = Application.CommandBars.Add("MY_TOOLBAR", 1, missing, true);
}
commandBar.Visible = true;
// addbutton:
docSaveButton = (Office.CommandBarButton)commandBar.Controls.Add(1, missing, missing, missing, missing);
docSaveButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon;
docSaveButton.Caption = "My save";
docSaveButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(docSaveButtonClick);
}
private void docSaveButtonClick(Office.CommandBarButton ctrl, ref bool cancel)
{
MessageBox.Show("Hello !", "Hello !", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Regards JanK