views:

100

answers:

1

I'm using this code to check if the standard toolbar is deactivated in the edit mode.

CommandBarControl oNewMenu = Application.CommandBars("Worksheet Menu Bar").FindControl(1, 18, 1, True, True)

If (IsNull(oNewMenu)) Then

        MsgBox "Edit mode enabled"

End If

but the FindControl function raise an error. Is there any conflict in the parameters?

A: 

I'm confused because the first statement will never compile. Moreover when evaluating existence of an object you should use 'Is Nothing' instead of 'IsNull'. Anyway try this:


Const CTRL_NEW = 2520

Dim oControl As CommandBarControl

Set oControl = CommandBars("Standard").FindControl(Id:=CTRL_NEW)

If Not oControl Is Nothing Then ' Control New is present in Standard bar'
    MsgBox "Edit mode " & IIf(oControl.Enabled, "enabled", "disabled"), vbInformation
End If
Emiel Nijhuis