Customizing private toolbars?

A

Alex

Hello,

My C# Word add-in adds a toolbar.

Is it possible to make this toolbar editable using Tools/Customize?
If so, how can I add a new category with my buttons/commands, so the user can drag them between toolbars?

Thank you!


Best wishes,
Alex.
 
P

Peter Huang [MSFT]

Hi Alex,

You may try to run the code below to see if this is what you want?

namespace MyWordAddin3
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using Word = Microsoft.Office.Interop.Word;
[GuidAttribute("66064ECA-5EA3-4CF1-87FD-EE14ABE68983"),
ProgId("MyWordAddin3.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
public Connect()
{
}
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
wdApp = application as Word.Application;
}
public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
}
public void OnAddInsUpdate(ref System.Array custom)
{
}
public void OnStartupComplete(ref System.Array custom)
{
cb = wdApp.CommandBars.Add("TestToolBar",oMissing,oMissing,oMissing);
cbb =

(CommandBarButton)cb.Controls.Add(MsoControlType.msoControlButton,oMissing,o
Missing,oMissing,oMissing);
cbb.Caption = "TestButton";
cbb.Click+=new _CommandBarButtonEvents_ClickEventHandler(cbb_Click);
}
public void OnBeginShutdown(ref System.Array custom)
{
}
object oMissing = System.Reflection.Missing.Value;
CommandBar cb;
CommandBarButton cbb;
private Word.Application wdApp=null;
private void cbb_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
System.Diagnostics.Debug.WriteLine("Clicked");
}
}
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Alex

Hello Peter,

Unfortunately, you did not address my question.

1) The button does not appear in the Tools/Customize dialog.

2) When I ran your code in Word, copied the button to another toolbar, then deleted it from the second toolbar - Word crashed.
 
P

Peter Huang [MSFT]

Hi

It is strange that you can not create the toolbar with the code.
If so, I think you may try to run the VBA code directly in the Macro to see
if that helps.
e.g.
Sub TestMacro()
Application.CommandBars.Add "Hello"
End Sub

Also I think you may try to run the the addin code on another machine to
see if that works.
Or
You may enbrace the add toolbar code in a try catch block to see if that
will catch any exception during button added.
2) When I ran your code in Word, copied the button to another toolbar,
then deleted it from the second toolbar - Word crashed.
Since my code is just for demo purpose, if you wants to use in your develop
environment, you may need to adjust.
Also what do you mean copy the button to another toolbar, can you show some
code to reproduce the problem?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi

Thanks for your picture!
Now I understand that you wants to add a word command but not a toolbar
according to the picture.
Based on my knowledge, the Word Command is all buildin, it did not expose
method for us to add new command associated to our addin method.
We can understand the Toolbar as a container of shortcuts.
The buildin Word Commands is divided by a few categories for us to arrange
them in the toolbars, and we can move their positions.
Also Word did provide the method for us to add a shortcut in the toolbar,
and associate the shortcut with our addin method.

So I think we did not create Word Command as the buildin command dialog, we
just associated our addin code with our created UI button on the toolbar
with the click or other event mechanism.

BTW: I have tried your reproduce steps, but I can not reproduced the
problem, i.e. the Word did not crash.
If you want the button to apprear in the standard toolbar, I think you may
try to add the commandbarcontrols to it directly.

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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