How to minimize / unMinimize the ribbon in Excel 2010 using C# 2010 (Vsto)

Answered How to minimize / unMinimize the ribbon in Excel 2010 using C# 2010 (Vsto)

  • Saturday, August 04, 2012 2:35 PM
     
     

    Hi 

    I have looked around but couldn't find how to do this. 

    Basically I want to create a button on a worksheet which minimize or unminimize the ribbon. 

    I was thinking it should be something like 

    if (this.application.MinimizeRibbon) 

    this.application.minimizeRibbon = false;
    }
    else 
    {
    this.application.minimizeRibbon = true;
    }

    I have tried 

    Application.SendKeys("^{F1}");

    Strangely, it turn on/off 'Num Lock' on the keyboard. 

    Anyone can help me out please? 

    Thanks. 

All Replies

  • Sunday, August 05, 2012 4:49 AM
     
     

    Do you mean so that you cannot see the ribbon. (In Excel it is under View ribbon -> Full Screen to hide the ribbon and display Full Screen. Esc returns to normal view with ribbon.)

    In VBA it is the following so maybe it will give you the hint for C# 2010 (Vsto)

        Application.DisplayFullScreen = True
        Application.DisplayFullScreen = False


    Regards, OssieMac

  • Thursday, August 09, 2012 9:17 AM
     
     

    Hi Thanks for the reply. 

    I am talking about minimization of ribbon by right click on the ribbon and tick 'minimize the ribbon' 

    But I think full screen display can be useful to my situation. 

    I am going to look into it.

    Thanks!!!!

  • Thursday, August 09, 2012 11:54 AM
     
     

    You can use SendKeys to toggle Minimize/Maximize the ribbon.

    Private Sub CommandButton1_Click()
        If Application.CommandBars.Item("Ribbon").Height > 81 Then
            CommandButton1.Caption = "Maximize Ribbon"
        Else
            CommandButton1.Caption = "Minimize Ribbon"
        End If
        SendKeys "^{F1}"
    End Sub

    Use the following to determine the height of the ribbon when Maximized and also when Minimized and you can use those values in the code above to determine the state (and set the button Caption as I have done) before using the SendKeys to toggle.

    MsgBox Application.CommandBars.Item("Ribbon").Height

    However, note that you cannot test it by running from the VBA Editor window because it will open Help. You need a button on the worksheet to test. If using an AxtiveX CommandButton then need to set the Property "TakeFocusOnClick" to False or the SendKeys does not work.


    Regards, OssieMac

  • Friday, August 10, 2012 6:31 AM
     
     

    Oh thanks.. 

    But in C#, I doesn't work. 

    'Item' Property is not there. 

    Can you tell me a equivalent code in c#? 

  • Monday, August 27, 2012 8:22 AM
    Moderator
     
     Answered

    Hi SQLMa,

    You've mentioned that sendkeys will turn off your numlock key. This scenario is an known issue and you can see it on this KB page.

    Hope it helps.

    Best regards,
    Quist


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us