Andrew Crawshaw

Hello Everyone,

In Word 2003 I'd like to manage the various menus and toolbars. The issue I'm having is that whilst I can find examples on how to create your own toolbars, I can't find anything that describes how to show or hide, for example, the Mail Merge toolbar.

What I'd like to do is the following:

1 Check if the Mail Merge toolbar is visible. Display the toolbar if it's not.

2 Execute the code the that the Open Data Source button uses to set the data source or

3 Set the Data Source programmatically.

Many thanks,

Andrew Crawshaw


(I realise this may not be strictly VSTO, so apologies if this is in the wrong forum.)

Re: Visual Studio Tools for Office Managing Toolbars

Ji Zhou – MSFT


I always use the following codes to get the whole list of Word’s CommandBars and CommandBarControls.

Code Block

//Create Word Application

Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();

//Create a new txt file to record controls' list

StreamWriter sw = System.IO.File.CreateText(@"C:\Word Command Bar Control List.txt");

//loop through wordApp.CommandBars to get all CommandBars

foreach (Office.CommandBar cb in wordApp.CommandBars)



//loop through each CommandBar's Controls collection to get all controls

foreach (Office.CommandBarControl cbc in cb.Controls)


sw.WriteLine("\t" + cbc.Caption);



Then you will find a text file in C:\ root directory. Open the file, search for Mail Merge, you can find the Mail Merge CommandBar and its controls.

Use these codes to show a CommandBar and execute a button’s function on the CommandBar:

Code Block

this.Application.CommandBars["Mail Merge"].Visible = true;

this.Application.CommandBars["Mail Merge"].Controls["&Open Data Source"].Execute();



Re: Visual Studio Tools for Office Managing Toolbars

Andrew Crawshaw

Hi Ji,

Thanks very much for that example of code, it's really helped me continue on with what I'm doing.