Creates a command bar that is saved and available the next time the environment is started.
Public Function AddCommandBar( _ ByVal Name As String, _ ByVal Type As vsCommandBarType, _ Optional ByVal CommandBarParent As CommandBar = Nothing, _ Optional ByVal Position As Integer = 1 _ ) As Object
Function AddCommandBar( _ ByVal Name As String, _ ByVal Type As vsCommandBarType, _ Optional ByVal CommandBarParent As CommandBar = Nothing, _ Optional ByVal Position As Long = 1 _ ) As Object
HRESULT __stdcall AddCommandBar( BSTR Name, vsCommandBarType Type, CommandBar* CommandBarParent, long Position, /* [out, retval] */ IDispatch** retVal );
public object AddCommandBar( string Name, vsCommandBarType Type, CommandBar CommandBarParent, int Position );
public function AddCommandBar( Name : String, Type : vsCommandBarType, CommandBarParent : CommandBar, 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 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.
Returns a CommandBar object.
The new command bar will be available during each new session of the environment regardless of whether the Add-in is loaded.
The CommandBar object is a member of the Microsoft Office object model.
Imports Microsoft.Office.Core 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 .NET 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", vsCommandBarType.vsCommandBarTypeToolbar) MsgBox("Commandbar name: " & cmdbarobj.Name) cmdobj = cmds.AddNamedCommand(colAddins.Item(1), "mycommand", "mycommand", "tooltip for mycommand", True) End Sub
Applies To: Commands Collection