creating custom tool bar for office application

R

Rita

We are adding a custom tool bar for MS Office applications Word and Outlook.
It is acting like a global toolbar to all active documents. We need a tool
bar instance for each active document separately.

We open a first MS Word instance and select the values from drop down
controls available in tool bar. After this we open another instance of MS
Word and the drop down values are same as selected in first instance.
 
K

Ken Slovak - [MVP - Outlook]

Is there a question? What is the problem?

How are you creating the toolbars, what version of Office, are you using
unique Tag properties for each one you create, what is your code, are you
handling the customization context of the Word templates, and so on.
 
R

Rita

Hi Ken

Thanks for the reply.

We are creating a custom commandbar for office 2003 -word, outlook, excel
and powepoint using visual studio 2003 extensibility project..

This commandbar will have 3 buttons and 3 dropdown. For each control we are
intializing unique tag property. Here we are handling click event for the
buttons and onchange event for dropdowns.
But the problem is that when we open a MS Word instance and select the
value from drop down controls available in command bar.
Now if we open another instance of MS Word we face following problem :
1.Drop down values are same as selected in first instance.
2.Also events are not getting fired for the second instance of the word.

We are creating the commanbar in the Onstartup event of Connect.cs. Is that
we have to create a new instance of toolbar when a document is opened.

Following code is used to create commandbar

// DECLARE
CommandBar oStandardBar = null;
Object oMissing = System.Reflection.Missing.Value;


oStandardBar = (CommandBar)oWord.CommandBars.Add("IAMWordToolbar",
MsoBarPosition.msoBarTop, oMissing, true);
oStandardBar.Protection=Microsoft.Office.Core.MsoBarProtection.msoBarNoChangeVisible;
oStandardBar.Visible = true;

// ADD CONTROLS IN TOOLBAR
if (oStandardBar != null)
{
// LEGAL ENTITY
cmbLegalEntity =
(CommandBarComboBox)oStandardBar.Controls.Add(MsoControlType.msoControlDropdown, oMissing, oMissing, oMissing, oMissing);
cmbLegalEntity.Caption =
dsLabel.Tables["locStrings"].Rows[0]["legal_entity"].ToString();
cmbLegalEntity.Style = MsoComboStyle.msoComboLabel;
cmbLegalEntity.Change += new
Microsoft.Office.Core._CommandBarComboBoxEvents_ChangeEventHandler(this.cmbLegalEntity_Change);
cmbLegalEntity.Width =250;
cmbLegalEntity.Tag="LegalEntity";
cmbLegalEntity.ListIndex = 0;

// HELP
btnHelpLegalEntity =
(CommandBarButton)oStandardBar.Controls.Add(MsoControlType.msoControlButton,
oMissing, oMissing, oMissing, true);
btnHelpLegalEntity.Visible = true;
btnHelpLegalEntity.Tag="LegalEntityHelp"
btnHelpLegalEntity.Style = MsoButtonStyle.msoButtonIconAndCaption;
btnHelpLegalEntity.FaceId = 984;
btnHelpLegalEntity.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnHelpLegalEntity_Click);

// SECURITY CLASSIFICATION
cmbSecurityClass =
(CommandBarComboBox)oStandardBar.Controls.Add(MsoControlType.msoControlDropdown, oMissing, oMissing, oMissing, oMissing);
cmbSecurityClass.Caption =
dsLabel.Tables["locStrings"].Rows[0]["secureity_class"].ToString();
cmbSecurityClass.Style = MsoComboStyle.msoComboLabel;
cmbSecurityClass.Change +=new
Microsoft.Office.Core._CommandBarComboBoxEvents_ChangeEventHandler(cmbSecurityClass_Change);
cmbSecurityClass.ListIndex = 0;
cmbSecurityClass.Tag="Security"

// HELP
btnHelpSecurityClass =
(CommandBarButton)oStandardBar.Controls.Add(MsoControlType.msoControlButton,
oMissing, oMissing, oMissing, true);
btnHelpSecurityClass.Visible = true;
btnHelpSecurityClass.Tag="SecurityHelp";
btnHelpSecurityClass.Style = MsoButtonStyle.msoButtonIconAndCaption;
btnHelpSecurityClass.FaceId = 984;
btnHelpSecurityClass.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnHelpSecurityClass_Click);

// RECORD TYPE
cmbRecordType =
(CommandBarComboBox)oStandardBar.Controls.Add(MsoControlType.msoControlDropdown, oMissing, oMissing, oMissing, oMissing);
cmbRecordType.Style = MsoComboStyle.msoComboLabel;
cmbRecordType.Change +=new
Microsoft.Office.Core._CommandBarComboBoxEvents_ChangeEventHandler(cmbRecordType_Change);
cmbRecordType.ListIndex=0;
cmbRecordType.Tag="RecordType";

// HELP
btnHelpRecordClass =
(CommandBarButton)oStandardBar.Controls.Add(MsoControlType.msoControlButton,
oMissing, oMissing, oMissing, true);
btnHelpRecordClass.Visible = true;
btnHelpRecordClass.Style = MsoButtonStyle.msoButtonIconAndCaption;
btnHelpRecordClass.FaceId = 984;
btnHelpRecordClass.Tag="RecordTypeHelp"
btnHelpRecordClass.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnHelpRecordClass_Click);
}}

Even tried setting CustomizationContext= OWord.ActiveDocument. But still its
not working. Can you tell what might be wrong in code?

Thanks
Rita
 
K

Ken Slovak - [MVP - Outlook]

You need to set up a new event handler for each document that opens and keep
a reference to that event handler somewhere that keeps it in scope so it's
not released, like a hashtable. You also should create a new and unique Tag
for each button you create, not only for each different button but for each
different instance of each button.

I'm not sure what you mean about the drop down values.




Rita said:
Hi Ken

Thanks for the reply.

We are creating a custom commandbar for office 2003 -word, outlook, excel
and powepoint using visual studio 2003 extensibility project..

This commandbar will have 3 buttons and 3 dropdown. For each control we
are
intializing unique tag property. Here we are handling click event for the
buttons and onchange event for dropdowns.
But the problem is that when we open a MS Word instance and select the
value from drop down controls available in command bar.
Now if we open another instance of MS Word we face following problem :
1.Drop down values are same as selected in first instance.
2.Also events are not getting fired for the second instance of the word.

We are creating the commanbar in the Onstartup event of Connect.cs. Is
that
we have to create a new instance of toolbar when a document is opened.

Following code is used to create commandbar

// DECLARE
CommandBar oStandardBar = null;
Object oMissing = System.Reflection.Missing.Value;


oStandardBar = (CommandBar)oWord.CommandBars.Add("IAMWordToolbar",
MsoBarPosition.msoBarTop, oMissing, true);
oStandardBar.Protection=Microsoft.Office.Core.MsoBarProtection.msoBarNoChangeVisible;
oStandardBar.Visible = true;

// ADD CONTROLS IN TOOLBAR
if (oStandardBar != null)
{
// LEGAL ENTITY
cmbLegalEntity =
(CommandBarComboBox)oStandardBar.Controls.Add(MsoControlType.msoControlDropdown,
oMissing, oMissing, oMissing, oMissing);
cmbLegalEntity.Caption =
dsLabel.Tables["locStrings"].Rows[0]["legal_entity"].ToString();
cmbLegalEntity.Style = MsoComboStyle.msoComboLabel;
cmbLegalEntity.Change += new
Microsoft.Office.Core._CommandBarComboBoxEvents_ChangeEventHandler(this.cmbLegalEntity_Change);
cmbLegalEntity.Width =250;
cmbLegalEntity.Tag="LegalEntity";
cmbLegalEntity.ListIndex = 0;

// HELP
btnHelpLegalEntity =
(CommandBarButton)oStandardBar.Controls.Add(MsoControlType.msoControlButton,
oMissing, oMissing, oMissing, true);
btnHelpLegalEntity.Visible = true;
btnHelpLegalEntity.Tag="LegalEntityHelp"
btnHelpLegalEntity.Style = MsoButtonStyle.msoButtonIconAndCaption;
btnHelpLegalEntity.FaceId = 984;
btnHelpLegalEntity.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnHelpLegalEntity_Click);

// SECURITY CLASSIFICATION
cmbSecurityClass =
(CommandBarComboBox)oStandardBar.Controls.Add(MsoControlType.msoControlDropdown,
oMissing, oMissing, oMissing, oMissing);
cmbSecurityClass.Caption =
dsLabel.Tables["locStrings"].Rows[0]["secureity_class"].ToString();
cmbSecurityClass.Style = MsoComboStyle.msoComboLabel;
cmbSecurityClass.Change +=new
Microsoft.Office.Core._CommandBarComboBoxEvents_ChangeEventHandler(cmbSecurityClass_Change);
cmbSecurityClass.ListIndex = 0;
cmbSecurityClass.Tag="Security"

// HELP
btnHelpSecurityClass =
(CommandBarButton)oStandardBar.Controls.Add(MsoControlType.msoControlButton,
oMissing, oMissing, oMissing, true);
btnHelpSecurityClass.Visible = true;
btnHelpSecurityClass.Tag="SecurityHelp";
btnHelpSecurityClass.Style = MsoButtonStyle.msoButtonIconAndCaption;
btnHelpSecurityClass.FaceId = 984;
btnHelpSecurityClass.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnHelpSecurityClass_Click);

// RECORD TYPE
cmbRecordType =
(CommandBarComboBox)oStandardBar.Controls.Add(MsoControlType.msoControlDropdown,
oMissing, oMissing, oMissing, oMissing);
cmbRecordType.Style = MsoComboStyle.msoComboLabel;
cmbRecordType.Change +=new
Microsoft.Office.Core._CommandBarComboBoxEvents_ChangeEventHandler(cmbRecordType_Change);
cmbRecordType.ListIndex=0;
cmbRecordType.Tag="RecordType";

// HELP
btnHelpRecordClass =
(CommandBarButton)oStandardBar.Controls.Add(MsoControlType.msoControlButton,
oMissing, oMissing, oMissing, true);
btnHelpRecordClass.Visible = true;
btnHelpRecordClass.Style = MsoButtonStyle.msoButtonIconAndCaption;
btnHelpRecordClass.FaceId = 984;
btnHelpRecordClass.Tag="RecordTypeHelp"
btnHelpRecordClass.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(btnHelpRecordClass_Click);
}}

Even tried setting CustomizationContext= OWord.ActiveDocument. But still
its
not working. Can you tell what might be wrong in code?

Thanks
Rita
 
B

Bob Eaton

You need to set up a new event handler for each document

Could you give a reference for how to set up an event handler (in VS.Net
2005 COM add-in) for when a document opens? I can't find any information on
this and it is especially a problem for Access: Access won't let you add
toobar buttons until a document is opened, but the IDTExtensibility
interface isn't called when a document is opened, but only at startup. If I
could detect no database opened at startup and add an event handler for
"open database", then I could add my menu items then, but I can't figure out
how to activate such an event handler...

Thanks,
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top