The macro below will only disable the 'Hide' option under Format>Row.
I've also included (but commented out) the code for enabling, hiding and
unhiding the Hide/Unhide options under the Format>Row menu.
I've also included a macro for the right-click menu. The reason is that,
even though you've disabled the Row>Hide option on the main menu, if the
client highlights the row and right clicks, guess what?!!, there's the 'Hide'
option!
I've included but commented out that ability also.
'/======================================/
Public Sub DisableMenuItem_Example()
'Disable / enable /hide / unhide a menu item such as
' Format>Row>Hide, etc
' - used when you don't want to let a user , for example,
' hide rows or columns
'
Dim objMenuItem As Object
Dim objSubMenuItem As Object
Dim objSub3MenuItem As Object
Dim strMainMenuItem As String
Dim strSubMenuItem As String
Dim strSub3MenuItem_Hide As String
Dim strSub3MenuItem_Unhide As String
'- - - - - - VARIABLES - - - - - - - - -
strMainMenuItem = "F&ormat" 'Main Menu Item
strSubMenuItem = "&Row" 'SubMenu Item
'&Column
strSub3MenuItem_Hide = "&Hide" ' 3rd Level Menu Item
strSub3MenuItem_Unhide = "&Unhide" ' 3rd Level Menu Item
'- - - - - - - - - - - - - - - - - - - -
For Each objMenuItem In _
CommandBars("Worksheet Menu Bar").Controls
If objMenuItem.Caption = strMainMenuItem Then
For Each objSubMenuItem In objMenuItem.Controls
If objSubMenuItem.Caption = strSubMenuItem Then
For Each objSub3MenuItem In objSubMenuItem.Controls
If objSub3MenuItem.Caption = _
strSub3MenuItem_Hide Or _
objSub3MenuItem.Caption = _
strSub3MenuItem_Unhide Then
'disable a menu item
objSub3MenuItem.Enabled = False
'enable a menu item
'objSub3MenuItem.Enabled = True
'hide a menu item
'objSub3MenuItem.Visible = False
'show a menu item
'objSub3MenuItem.Visible = True
'disable the Row>Hide option on the Cell menu
'Call DisableCellMenuItem
'enable the Row>Hide option on the Cell menu
'Call EnableCellMenuItem
End If
Next objSub3MenuItem
End If
Next objSubMenuItem
Exit For
End If
Next objMenuItem
End Sub
'/======================================/
Public Sub DisableCellMenuItem()
'
Dim objMenuItem As Object
Dim strHide As String, strUnhide As String
'- - - - - - VARIABLES - - - - - - - - -
strHide = "&Hide" 'item #1 to find
strUnhide = "&Unhide" 'item #1 to find
'- - - - - - - - - - - - - - - - - - - -
For Each objMenuItem In CommandBars("ROW").Controls
If objMenuItem.Caption = strHide Or _
objMenuItem.Caption = strUnhide Then
objMenuItem.Enabled = False 'disable a menu item
End If
Next objMenuItem
End Sub
'/======================================/
Public Sub EnableCellMenuItem()
'
Dim objMenuItem As Object
Dim strHide As String, strUnhide As String
'- - - - - - VARIABLES - - - - - - - - -
strHide = "&Hide" 'item #1 to find
strUnhide = "&Unhide" 'item #1 to find
'- - - - - - - - - - - - - - - - - - - -
For Each objMenuItem In CommandBars("ROW").Controls
If objMenuItem.Caption = strHide Or _
objMenuItem.Caption = strUnhide Then
objMenuItem.Enabled = True 'enable a menu item
End If
Next objMenuItem
End Sub
'/======================================/
--
HTH,
Gary Brown
(e-mail address removed)
If this post was helpful to you, please select ''YES'' at the bottom of the
post.