ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   right click hide (https://www.excelbanter.com/excel-programming/392782-right-click-hide.html)

General[_2_]

right click hide
 
I would like to add a 'hide sheet' option to the right click menu per tab.
Can you help please?

Chip Pearson

right click hide
 
Try code like the following:



Sub AddMenuItem()
RemoveMenuItem
With Application.CommandBars("Ply").Controls.Add( _
Type:=msoControlButton, temporary:=True)
.Caption = "Hide The Sheet"
.OnAction = "'" & ThisWorkbook.Name & "'!HideTheSheet"
.Tag = "__HIDE_SHEET__"
End With
End Sub

Sub HideTheSheet()
Dim VisCount As Long
Dim WS As Worksheet
For Each WS In ActiveWorkbook.Worksheets
If WS.Visible = xlSheetVisible Then
VisCount = VisCount + 1
End If
Next WS
If VisCount 1 Then
ActiveSheet.Visible = xlSheetHidden
End If
End Sub

Sub RemoveMenuItem()
On Error Resume Next
Application.CommandBars.FindControl(Tag:="__HIDE_S HEET__").Delete
End Sub



"General" wrote in message
...
I would like to add a 'hide sheet' option to the right click menu per tab.
Can you help please?




All times are GMT +1. The time now is 05:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com