Application.IsCommandEnabled method (Project)

Shows whether the specified command is enabled.

Syntax

expression. IsCommandEnabled( _CommandName_ )

expression An expression that returns an Application object.

Parameters

Name Required/Optional Data type Description
CommandName Required String The name of a valid command.

Return value

Long

Remarks

Valid commands are VBA method names in the MSProject library. The return value can be one of the PjIsCommandEnabled constants.

Example

When the Team Planner view is not visible, the TestCommandEnabled macro returns the following results:

The FileOpen method is available in most cases. The IsCommandEnabled method is undefined because it is not included in the internal list of methods. The ResetTPStyle method is disabled because it is only available when the Team Planner view is open.

Sub TestCommandEnabled() 
 Dim commandArray(3) As String 
 Dim isEnabled As String 
 Dim i As Integer 
 
 commandArray(1) = "FileOpen" 
 commandArray(2) = "IsCommandEnabled" 
 commandArray(3) = "ResetTPStyle" 
 
 For i = 1 To 3 
 isEnabled = GetCommandEnabled(commandArray(i)) 
 Debug.Print commandArray(i) & " is " & isEnabled 
 Next i 
End Sub 
 
Function GetCommandEnabled(command As String) As String 
 Dim isEnabled As Long 
 Dim enabledMsg As String 
 Dim result As String 
 
 isEnabled = Application.IsCommandEnabled(command) 
 
 Select Case isEnabled 
 Case PjIsCommandEnabled.pjCommandDisabled 
 result = "disabled." 
 Case PjIsCommandEnabled.pjCommandEnabled 
 result = "enabled." 
 Case PjIsCommandEnabled.pjCommandUndefined 
 result = "undefined." 
 Case Else 
 result = "unknown result." 
 End Select 
 
 GetCommandEnabled = result 
End Function

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.