Show/Hide toolbars for current workbook only

  • I have a macro that starts when the workbook is open that hides many of the headers and toolbars. It is great and works fine unless you are working on another workbook and need to see those headers and tool bars. Is there a way to display and hide those items per workbook and not for the entire application. here is my failed attempt:




    Any help is appreciated.


    Guy

  • Re: Show/Hide toolbars for current workbook only


    Hi, GuyGadois,


    you may have a good look at ThisWorkbook and the Private Sub Workbook_WindowDeactivate(ByVal Wn As Excel.Window) and Private Sub Workbook_WindowActivate(ByVal Wn As Excel.Window) events to call your codes when changing workbooks.


    Ciao,
    Holger

  • Re: Show/Hide toolbars for current workbook only


    Guy


    I wouldn't recommend this approach, it can cause real aggro for your users if for instance Excel crashes & doen't restore everything back to the original settings

  • Re: Show/Hide toolbars for current workbook only


    I would use the Workbook Active and Deactivate to do this. E.g

  • Re: Show/Hide toolbars for current workbook only


    Dave, I implemented your code below. First, I get a Run-time error:


    Run Time error '-2147467259 (80004005)':
    Method 'Visible' of object 'CommandBar' failed


    at the following


    Code
    wb.Application.CommandBars("Worksheet Menu Bar").Visible = False


    Also, your code still doesn't seem to do the trick. When I am on, for instance, workbook 2 and click to show headers it shows headers for all workbooks currently open. I only want the code to make the view changes on the active workbook. Even if I have 5 workbooks open I only want the view changes to take place on the active workbook. Here is what I have so far...




    Code
    Private Sub Workbook_Activate()
        On Error Resume Next
        Run "hide_excel_headers"
        On Error GoTo 0
    End Sub


    Code
    Private Sub Workbook_Deactivate()
        On Error Resume Next
        Run "show_excel_headers"
        On Error GoTo 0
    End Sub



    Quote from Dave Hawley

    I would use the Workbook Active and Deactivate to do this. E.g

  • Re: Show/Hide toolbars for current workbook only


    Thanks Dave - you have saved my bacon again! Your suggested code works fine for the app I'm working on at the moment too - but with one minor alteration.
    'Run' doesn't seem to call my required 'subs' but using 'call' does.
    Any ideas why please?


    Quote from Dave Hawley

    I would use the Workbook Active and Deactivate to do this. E.g

  • Re: Show/Hide toolbars for current workbook only


    Quote

    'Run' doesn't seem to call my required 'subs' but using 'call' does.

    Are the macros in a standard module? What happens when you use Run?

  • Re: Show/Hide toolbars for current workbook only


    They are all 'Private Sub's in the 'ThisWorkbook' object(?) of the spreadsheet.
    When using 'Run' the execution just steps right through that line without apparently doing anything.
    I have appended the code I am using in case it helps...


  • Re: Show/Hide toolbars for current workbook only


    Only the Event procedures of the Private module should be in there. All other procedures should be in a standard public module.


    Howewer, to call a Private Sub in the same Private Module, you simply put the Procedures name. E.g

    Code
    Private Sub Workbook_Deactivate() 
        On Error Resume Next 
        Display_User_Toolbars 
        On Error Goto 0 
    End Sub
  • Re: Show/Hide toolbars for current workbook only


    Hi,


    change visible to enable.


    wb.Application.CommandBars("Worksheet Menu Bar").Enabled = False

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!