All menu items have a unique ID.
This code will give you the ID for a given menu option:
e.g. FindMenuID "&Paste" will display the ID 22.
Sub FindMenuItemID(strCaption As String)
Dim cb As CommandBar
Dim cbc As CommandBarControl
For Each cb In CommandBars
For Each cbc In cb.Controls
If cbc.Caption = strCaption Then
MsgBox "The ID for '" & strCaption & "' is " & cbc.ID
Exit Sub
End If
Next
Next
MsgBox "Cannot find control with caption of '" & strCaption & "'"
End Sub
Once you know the ID, this code will enable or disable ALL the controls with the same ID.
e.g. 'EnableControls 22,false' will disable all paste commands
Sub EnableControls(lngID As Long, blnEnable As Boolean)
Dim cbcs As CommandBarControls
Dim lngIndex As Long
Set cbcs = Application.CommandBars.FindControls(ID:=lngID)
If cbcs Is Nothing Then Exit Sub
For lngIndex = 1 To cbcs.Count
cbcs(lngIndex).Enabled = blnEnable
Next
End Sub
For this code to work you must set a Reference to Microsoft Office object library.
HTH.
M *<|
