Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
AddCommandBar
Cut
Run
Collapse the table of content
Expand the table of content

AddCommandBar Method

Visual Studio .NET 2003

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

[Visual Basic .NET]
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
[Visual Basic 6]
Function AddCommandBar( _
   ByVal Name As String, _
   ByVal Type As vsCommandBarType, _
   Optional ByVal CommandBarParent As CommandBar = Nothing, _
   Optional ByVal Position As Long = 1 _
) As Object
[C++]
HRESULT __stdcall AddCommandBar(
   BSTR Name,
   vsCommandBarType Type,
   CommandBar* CommandBarParent,
   long Position,
   /* [out, retval] */ IDispatch** retVal
);
[C#]
public object AddCommandBar(
   string Name,
   vsCommandBarType Type,
   CommandBar CommandBarParent,
   int Position
);
[JScript .NET]
public function AddCommandBar(
   Name : String,
   Type : vsCommandBarType,
   CommandBarParent : CommandBar,
   Position : int
) : Object

Parameters

Name
Required. A name for the new command bar.
Type
Required. A vsCommandBarType constant that determines the type of command bar:
CommandBarParent
Optional. An Office CommandBar object to which the new command bar is to be added. (This is required, however, if Type is vsCommandBarTypeMenu.)
Position
Optional. The index position, starting at one, in the command bar to place the new command bar.

Return Value

Returns a CommandBar object.

Remarks

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.

Example

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

See Also

Applies To: Commands Collection

Show:
© 2015 Microsoft