Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
code:
----------------------------------------------------------- 'At top of this module Dim MyBar As CommandBar Dim MadeButton As CommandBarButton Dim Page1Button As CommandBarButton Dim Page2Button As CommandBarButton Dim Page3Button As CommandBarButton Dim Sheetname As String Sub CustomToolbar 'code to set up toolbar and assign other buttons MakeButton ("Page1") MakeButton ("Page2") MakeButton ("Page3") 'other code End sub Sub MakeButton(Sheetname) Set MadeButton = MyBar.Controls.Add (Type:=msoControlButton) With MadeButton .Style = msoButtonIconAndCaption If Worksheets(Sheetname).Visible < -1 Then .Caption = "Show '" & Sheetname & "'" .FaceId = 170 .State = msoButtonUp Else .Caption = "Hide '" & Sheetname & "'" .FaceId = 171 .State = msoButtonDown End If .OnAction = "'HideShow """ & Sheetname & """'" End With End Sub Sub HideShow(Sheetname) If Worksheets(Sheetname).Visible = -1 Then Worksheets(Sheetname).Visible = 2 Else: Worksheets(Sheetname).Visible = -1 Worksheets(Sheetname).Select End If FinishToolBar End Sub ----------------------------------------------------------- When a user has their Tools, Macro, Security, Security Levels, set to Low, this Macro runs just fine. However when they have it set to Medium (and they Enable Macros), they can click on one of these buttons, but no sheets are made visible or hidden. Trying to figure it out, when I put MsgBox Sheetname as the first line of HideShow, it never pops up. So it looks like the .onaction event is disabled by the medium security level setting. Does this make any sense? I know how to get around this (hard code the buttons instead using loops and variables, or I can require that the users set their Security to Low) so that isn't my question. My question is what do I do to get this work, or same thing is different between Low and Medium-Enable. Thank you all so much! |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The code in my first post was not as complete as it could
have been. If anyone wanted to load the code and test it, I wanted it as perfect as possible. 'At top of this module Dim MyBar As CommandBar Dim MadeButton As CommandBarButton Dim Page1Button As CommandBarButton Dim Page2Button As CommandBarButton Dim Page3Button As CommandBarButton Dim Sheetname As String Sub DeleteToolBar() 'I didn't show this macro in my original post On Local Error Resume Next MyBar.Delete On Local Error GoTo 0 End Sub Sub CustomToolbar DeleteToolBar 'I didn't show this line in my original post Set MyBar = CommandBars.Add("CustomToolbar", msoBarFloating, , Temporary:=True) 'I didn't show this line in my original post MakeButton ("Page1") MakeButton ("Page2") MakeButton ("Page3") 'other code With MyBar 'This 'With MyBar' was not shown in my original post .Protection = msoBarNoChangeVisible + msoBarNoResize .Width = 150 .Visible = True .Top = 600 .Left = 700 End With End sub Sub MakeButton(Sheetname) Set MadeButton = MyBar.Controls.Add (Type:=msoControlButton) With MadeButton .Style = msoButtonIconAndCaption If Worksheets(Sheetname).Visible < -1 Then .Caption = "Show '" & Sheetname & "'" .FaceId = 170 .State = msoButtonUp Else .Caption = "Hide '" & Sheetname & "'" .FaceId = 171 .State = msoButtonDown End If .OnAction = "'HideShow """ & Sheetname & """'" End With End Sub Sub HideShow(Sheetname) If Worksheets(Sheetname).Visible = -1 Then Worksheets(Sheetname).Visible = 2 Else: Worksheets(Sheetname).Visible = -1 Worksheets(Sheetname).Select End If CustomToolBar 'my original posting had FinishToolBar End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VBA macro runs fine, but freezes if I try to do ANYTHING else whileit runs | Setting up and Configuration of Excel | |||
EXCEL: the best tool for Small and Medium sized businesses | Links and Linking in Excel | |||
ABC C39 Medium Text Font | Excel Discussion (Misc queries) | |||
Macro security level in excel will not change to medium or low | Setting up and Configuration of Excel | |||
How can i create a scatterplot with small and medium values? | Charts and Charting in Excel |