• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

hide menus & toolbars for only one worksheet

Marco1975

New Member
hi.
I am using macros that hide menu and toolbars ; the problem is that when I run the macros in all open workbooks are hidden menus and toolbars . Instead the macro should run only for the workbook where it is performed . How can I do to solve this problem?
These are macros that use :

Code:
Sub All_Sheets_on()
Dim sht As Worksheet

For Each sht In ThisWorkbook.Worksheets
Application.ScreenUpdating = False
Application.DisplayScrollBars = False
Application.DisplayFormulaBar = False
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayGridlines = False
Application.DisplayFullScreen = True
Application.DisplayStatusBar = False
Application.WindowState = xlMaximized
ActiveWindow.WindowState = xlMaximized

Application.ScreenUpdating = True
Next
End Sub

Code:
Sub All_Sheets_off()
Dim sht As Worksheet
For Each sht In ThisWorkbook.Worksheets


Application.ScreenUpdating = False
Application.DisplayScrollBars = True
Application.DisplayFormulaBar = True
ActiveWindow.View = xlNormalView
ActiveWindow.DisplayHeadings = True
ActiveWindow.DisplayGridlines = True
Application.DisplayStatusBar = True
ActiveWindow.DisplayHorizontalScrollBar = True
ActiveWindow.DisplayVerticalScrollBar = True
Application.DisplayFullScreen = False

Application.ScreenUpdating = True

Next
End Sub

Thank you.
 
I'd put the macros in the ThisWorkbook module, and use the Workbook_Activate and Workbook_Deactivate event macros.
 
Marco --

Maybe you're new to VBA like I am?

I think the problem is that the code you have provided is not directing the properties of a given Worksheet. Nor is it directing the properties of a given Workbook.

It is directing the properties of a given occurrence of the Application.

This means that the loop you've created to apply your change to each Worksheet in a designated book is unnecessary. (The macro will perform the same way even if you delete the loop.)

Luke's suggestion makes sense to me: Tie the macro to an event, namely, the activation of the specific workbook where you want the menus to be hidden. When you deactivate the workbook (by selecting another workbook), then your code will automatically restore the menus.

In any case, the code itself will continue to modify the Application -- not the Workbook; but it will toggle on and off based on whether the target workbook is active.

All best.
 
Back
Top