This documentation is archived and is not being maintained.

RemoveCommandBar Method

Visual Studio .NET 2003

Removes a command bar that was created with the AddCommandBar method.

[Visual Basic .NET]
Public Sub RemoveCommandBar( _
   ByVal CommandBar As CommandBar _
) 
[Visual Basic 6]
Sub RemoveCommandBar( _
   ByVal CommandBar As CommandBar _
) 
[C++]
HRESULT __stdcall RemoveCommandBar(
   CommandBar* CommandBar
);
[C#]
public void RemoveCommandBar(
   CommandBar CommandBar
);
[JScript .NET]
public function RemoveCommandBar(
   CommandBar : CommandBar
)

Parameters

CommandBar
Required. The CommandBar object to remove.

Remarks

RemoveCommandBar fails if the command bar is intrinsic (built-in) to the environment.

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

Example

Imports Microsoft.Office.Core
Sub RemoveCommandBarExample()
   ' 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.AddControl(cmdbarobj)
   cmds.AddNamedCommand(colAddins.Item(1), "MyCommand", "Button Text", "Some tooltip", True)
   cmds.RemoveCommandBar(cmdbarobj)
End Sub

See Also

Applies To: Commands Collection

Show: