Hide Menu Ribbon Only this Workbook

NextYearSox

Active Member
Joined
Oct 24, 2003
Messages
287
I am using the following VBA code to hide/unhide the menu ribbon. Is there a way that I can restrict this to only the one workbook? Any other open EXCEL workbooks also have their menus hidden ... ugh

Private Sub Auto_Open()
Application.ScreenUpdating = False

Application.ExecuteExcel4Macro "Show.Toolbar(""Ribbon"",False)"
Application.DisplayFormulaBar = False
Application.DisplayStatusBar = Not Application.DisplayStatusBar
ActiveWindow.DisplayWorkbookTabs = False
ActiveWindow.DisplayHeadings = False
ActiveWindow.DisplayHorizontalScrollBar = False
ActiveWindow.DisplayVerticalScrollBar = False

End Sub

Private Sub Auto_Close()

Application.ExecuteExcel4Macro "Show.Toolbar(""Ribbon"",True)"
Application.DisplayFormulaBar = True
Application.DisplayStatusBar = True
ActiveWindow.DisplayWorkbookTabs = True
ActiveWindow.DisplayHeadings = True
ActiveWindow.DisplayHorizontalScrollBar = True
ActiveWindow.DisplayVerticalScrollBar = True

End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Instead of using the Auto_Open and Auto_Close events, use the Workbook_Activate and Workbook_Deactivate events...

Code:
Private Sub Workbook_Activate()
    '
    '
    '
End Sub

Private Sub Workbook_Deactivate()
    '
    '
    '
End Sub

Hope this helps!
 
Upvote 0
I tried this and can't get it to work. I am calling these from a Module, and when I launch the file the subroutine doesn't execute. If I put these into ThisWorkbook, the subroutine's launch, but then I can't select another workbook. Everytime I try and do so, the subroutine executes again.

Am I missing something?
 
Upvote 0
The Workbook_Activate and Workbook_Deactivate events should go in the code module for ThisWorkbook, and should work like this...

1) When the workbook is opened, the Workbook_Activate event is triggered, and the ribbon is hidden, etc.

2) When another workbook is either opened or activated, the Workbook_Deactivate event from the first workbook is triggered, and the ribbon is shown.

3) And if the first workbook is activated, the Workbook_Activate event is triggered, and the ribbon is hidden again.

4) And if the workbook is closed, the Workbook_Deactivate event is triggered, and the ribbon is shown.

Isn't this what you're looking for?
 
Upvote 0
This process didn't work initially. I monkeyed around with my activate/deactivate subroutines and discovered that the following was monkeying everything up:

On Workbook_Activate ...
For Each WorksheetTab In Worksheets
WorksheetTab.Activate
ActiveWindow.DisplayHeadings = False
Next WorksheetTab

On Workbook Deactivate ...
For Each WorksheetTab In Worksheets
WorksheetTab.Activate
ActiveWindow.DisplayHeadings = False
Next WorksheetTab

Once I commented these out, everything functioned as you described ... thank you.

The purpose of the preceding was to hide (unhide) the column and Row headers. Is there an easer way to accomplish this?
 
Upvote 0
For the display headings, why not simply set it manually? Otherwise, since the settings are workbook specific, try placing them in the Workbook_Open and Workbook_BeforeClose events.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top