PC Review


Reply
Thread Tools Rate Thread

Disable custom menu item based on visible cells

 
 
stewart
Guest
Posts: n/a
 
      1st Jan 2008
I have a custom excel menu that is paired with a scheduling
worksheet. My worksheet has two sections: the actual schedule A1:O16
and the payroll information P1:T16. I have two menu items one that
will show the payroll information and one that will hide it. I would
like to have just one menu item that will change to Hide or Show
depending on the visibility of the payroll section. Below is the
code. Is it possible?


***Module 1***
Sub AddMenus()
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCutomMenu As CommandBarControl
Dim imenuindex As Integer

On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&Schedule
Tools").Delete
On Error GoTo 0

Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
iHelpMenu = cbMainMenuBar.Controls("Help").Index
Set cbcCutomMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup,
Before:=iHelpMenu)
cbcCutomMenu.Caption = "&Schedule Tools"

With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Show Detail"
.OnAction = "ShowDetail"
End With
With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Hide Detail"
.OnAction = "HideDetail"
End With


***Module 2***
Sub ShowDetail()
Application.ScreenUpdating = False
ActiveSheet.Unprotect

Rows("47:48").Select
Selection.EntireRow.Hidden = False
Columns("P:R").Select
Selection.EntireColumn.Hidden = False

'Fit Sheet to Screen
Range("a:s").Select
ActiveWindow.Zoom = True
Range("a2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
Application.ScreenUpdating = False
End Sub

Sub HideDetail()
Application.ScreenUpdating = False
ActiveSheet.Unprotect

Rows("47:48").Select
Selection.EntireRow.Hidden = True
Columns("P:R").Select
Selection.EntireColumn.Hidden = True

'Fit Sheet to Screen
Range("a:s").Select
ActiveWindow.Zoom = True
Range("a2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
Application.ScreenUpdating = False
End Sub
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      1st Jan 2008

Something along the lines of...
'--
Sub ShowAndHideDetails
If ActionControl.Caption = "Hide" Then
'Code to hide the rows
ActionControl.Caption = "Show"
Else
'Code to show the rows
ActionControl.Caption = "Hide"
End If
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)




"stewart"
<(E-Mail Removed)>
wrote in message
I have a custom excel menu that is paired with a scheduling
worksheet. My worksheet has two sections: the actual schedule A1:O16
and the payroll information P1:T16. I have two menu items one that
will show the payroll information and one that will hide it. I would
like to have just one menu item that will change to Hide or Show
depending on the visibility of the payroll section. Below is the
code. Is it possible?


***Module 1***
Sub AddMenus()
Dim cMenu1 As CommandBarControl
Dim cbMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim cbcCutomMenu As CommandBarControl
Dim imenuindex As Integer

On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("&Schedule
Tools").Delete
On Error GoTo 0

Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
iHelpMenu = cbMainMenuBar.Controls("Help").Index
Set cbcCutomMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup,
Before:=iHelpMenu)
cbcCutomMenu.Caption = "&Schedule Tools"

With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Show Detail"
.OnAction = "ShowDetail"
End With
With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Hide Detail"
.OnAction = "HideDetail"
End With


***Module 2***
Sub ShowDetail()
Application.ScreenUpdating = False
ActiveSheet.Unprotect

Rows("47:48").Select
Selection.EntireRow.Hidden = False
Columns("P:R").Select
Selection.EntireColumn.Hidden = False

'Fit Sheet to Screen
Range("a:s").Select
ActiveWindow.Zoom = True
Range("a2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
Application.ScreenUpdating = False
End Sub

Sub HideDetail()
Application.ScreenUpdating = False
ActiveSheet.Unprotect

Rows("47:48").Select
Selection.EntireRow.Hidden = True
Columns("P:R").Select
Selection.EntireColumn.Hidden = True

'Fit Sheet to Screen
Range("a:s").Select
ActiveWindow.Zoom = True
Range("a2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True
Application.ScreenUpdating = False
End Sub
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Menu Item Access Keys Not visible xakee Microsoft Dot NET Framework Forms 1 21st Apr 2008 07:31 AM
Disable custom menu item =?Utf-8?B?TWlrZSBSb2JpbnNvbg==?= Microsoft Access 2 20th Sep 2006 11:56 PM
custom form as forwarded item not visible in other Exchange org a6avant@hotmail.com Microsoft Outlook Form Programming 9 6th May 2006 12:00 PM
How to disable the "Insert Copied Cells" context menu item =?Utf-8?B?Q29lbg==?= Microsoft Excel Programming 21 9th Feb 2005 09:37 PM
I create a menu item using VB, within a custom contacts form. I do not want the item to be visible in other forms or views. How do I do this?? Tore Microsoft Outlook Form Programming 0 10th Mar 2004 01:03 PM


Features
 

Advertising
 

Newsgroups
 


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