This documentation is archived and is not being maintained.

Commands.AddCommandBar Method

Creates a command bar that is saved and available the next time the environment is started.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

Object AddCommandBar (
	[InAttribute] string Name,
	[InAttribute] vsCommandBarType Type,
	[OptionalAttribute] [InAttribute] Object CommandBarParent,
	[OptionalAttribute] [InAttribute] int Position
Object AddCommandBar (
	/** @attribute InAttribute() */ String Name, 
	/** @attribute InAttribute() */ vsCommandBarType Type, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ Object CommandBarParent, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ int Position
function AddCommandBar (
	Name : String, 
	Type : vsCommandBarType, 
	CommandBarParent : Object, 
	Position : int
) : Object



Required. A name for the new command bar.


Required. A vsCommandBarType constant that determines the type of command bar:


Optional. An Office Microsoft.VisualStudio.CommandBars.CommandBar object to which the new command bar is to be added. (This is required, however, if Type is vsCommandBarTypeMenu.)


Optional. The index position, starting at one, in the command bar to place the new command bar.

Return Value

A Microsoft.VisualStudio.CommandBars.CommandBar object.

The new command bar is available during each new session of the environment regardless of whether the Add-in is loaded.

The Microsoft.VisualStudio.CommandBars.CommandBar object is a member of the Microsoft Office object model.

' Macro code.
Imports Microsoft.VisualStudio.CommandBars
Sub AddCommandBarExample()
   ' Before running, you must add a reference to the Office 
   ' typelib to gain access to the CommandBar object. Also, for this 
   ' example to work correctly, there should be an add-in available 
   ' in the Visual Studio environment.
   Dim cmds As Commands
   Dim cmdobj As Command
   Dim customin, customout As Object
   Dim cmdbarobj As CommandBar
   Dim colAddins As AddIns

   ' Set references.
   colAddins = DTE.AddIns()
   cmds = DTE.Commands
   cmdobj = cmds.Item("File.NewFile")

   ' Create a toolbar and add the File.NewFile command to it.
   cmdbarobj = cmds.AddCommandBar("Mycmdbar", _
   MsgBox("Commandbar name: " & cmdbarobj.Name)
   cmdobj = cmds.AddNamedCommand(colAddins.Item(1), "mycommand", _
   "mycommand", "tooltip for mycommand", True)
End Sub