Export (0) Print
Expand All
Cut
Run
Expand Minimize

AddNamedCommand Method

Visual Studio .NET 2003

Creates a named command that is saved by the environment and made available the next time the environment starts, even if the Add-in is not loaded on environment startup.

[Visual Basic .NET]
Public Function AddNamedCommand( _
   ByVal pAddIn As AddIn, _
   ByVal Name As String, _
   ByVal ButtonText As String, _
   ByVal Tooltip As String, _
   ByVal MSOButton As Boolean, _
   Optional ByVal Bitmap As Integer = 0, _
   ByVal ppsaContextUIGUIDs() As Object, _
   Optional ByVal DisableFlags As Integer = 16 _
) As Command
[Visual Basic 6]
Function AddNamedCommand( _
   ByVal pAddIn As AddIn, _
   ByVal Name As String, _
   ByVal ButtonText As String, _
   ByVal Tooltip As String, _
   ByVal MSOButton As Boolean, _
   Optional ByVal Bitmap As Long = 0, _
   ByVal ppsaContextUIGUIDs() As Variant, _
   Optional ByVal DisableFlags As Long = 16 _
) As Command
[C++]
HRESULT __stdcall AddNamedCommand(
   AddIn* pAddIn,
   BSTR Name,
   BSTR ButtonText,
   BSTR Tooltip,
   VARIANT_BOOL MSOButton,
   long Bitmap,
   SAFEARRAY** ppsaContextUIGUIDs,
   long DisableFlags,
   /* [out, retval] */ Command** retVal
);
[C#]
public Command AddNamedCommand(
   AddIn pAddIn,
   string Name,
   string ButtonText,
   string Tooltip,
   bool MSOButton,
   int Bitmap,
   object[] ppsaContextUIGUIDs,
   int DisableFlags
);
[JScript .NET]
public function AddNamedCommand(
   pAddIn : AddIn,
   Name : String,
   ButtonText : String,
   Tooltip : String,
   MSOButton : Boolean,
   Bitmap : int,
   ppsaContextUIGUIDs : Object[],
   DisableFlags : int
) : Command

Parameters

pAddin
Required. The Addin Object that is adding the new command.
Name
Required. The short form of the name for your new command. AddNamedCommand prefaces this with "Addins.Progid." to create a unique name.
ButtonText
Required. The name to use if the command is bound to a button that is displayed by name rather than by icon.
ToolTip
Required. The text displayed when a user hovers the mouse pointer over any control bound to the new command.
MSOButton
Required. Indicates whether the named command's button picture is an Office picture. True = button. If MSOButton is False, then Bitmap is the ID of a 16x16 bitmap resource (but not an icon resource) in a Visual C++.NET resource DLL that must reside in a folder with the language's locale identifier (1033 for English).
Bitmap
Optional. The ID of a bitmap to display on the button.
ppsaContextUIGUIDs
Optional. A SafeArray of GUIDs that determines which environment contexts (that is, debug mode, design mode, and so on) enable the command. See DisableFlags.
DisableFlags
Optional. Determines whether the disabled state of the command is invisible or grey when you supply a ContextUIGUIDs and none are currently active.

Return Value

Returns a Command object.

Remarks

Add-ins can later change the ButtonText name by responding to the QueryStatus Method. If the text begins with "#", then the rest of the string is an integer that represents a resource ID in the Add-in's registered satellite DLL.

ppsaContextUIGUIDs is used when the Add-in is not loaded and thus cannot respond to the QueryStatus method. If ppsaContextUIGUIDs is empty, then the command is enabled until the Add-in is loaded and can respond to QueryStatus.

The Add-in can receive invocation notification through the IDTCommandTarget interface. A button can be added using the OnConnection Method of the IDTExtensibility2 Interface.

Example

Imports Microsoft.Office.Core
Sub AddControlExample()
   ' 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 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.
   cmds.AddCommandBar("Mycmdbar", vsCommandBarType.vsCommandBarTypeToolbar)
   MsgBox("Commandbar name: " & cmdbarobj.Name)
   cmdobj.AddControl(cmdbarobj)
   cmds.AddNamedCommand(colAddins.Item(1), "MyCommand", "Button Text", "Some tooltip", True)
End Sub

See Also

Applies To: Commands Collection

Show:
© 2014 Microsoft