right click hide

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to add a 'hide sheet' option to the right click menu per tab.
Can you help please?
 
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_SHEET__").Delete
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top