Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dear All,

I'm creating windows application in c#, where automating MsOffice Excel.

I'm trying to get excel application ribbon is currently hide/show.

Following code:

What I have tried:

public static bool EvaluateRibbonDisplay(IQuestion question, string filename, ShowHide display)
{
    ExcelInterop.Application excelApplication = null;
    try
    {
        excelApplication = new ExcelInterop.Application() { Visible = false, DisplayAlerts = false, ScreenUpdating = false };
        ExcelInterop.Workbook excelWorkbook = excelApplication.Workbooks.Open(filename);

        bool result = false;
        var abc = excelApplication.ExecuteExcel4Macro("Get.ToolBar(7,\"Ribbon\")"); \\always returing true
        var abcd = excelApplication.CommandBars["Get.ToolBar(7,\"Ribbon\")"].Enabled;\\always returing true
        if (excelApplication.ExecuteExcel4Macro("Get.ToolBar(7,\"Ribbon\")") == Convert.ToBoolean(EnumStringExtension.GetDescription(display)))
            result = true;

        excelWorkbook.Close();

        return result;
    }
    catch (Exception)
    {
        return false;
    }
    finally
    {
        QuitApplication(excelApplication);
    }
}


to hide/show the ribbon, i use Ctrl+F1. But the above code is returning always true.

can anyone please help me, how can i get the ribbon status.

Thanks in advance.
Posted
Updated 6-Jun-17 1:16am

1 solution

 
Share this answer
 
Comments
Patrice T 6-Jun-17 7:24am    
I fear it is the answer to the previous question of this Q/A vampire. :-)
abdul subhan mohammed 6-Jun-17 8:20am    
in both the questions, when i'm trying hide/show the ribbon, by code.. is not working,
nor i can't evaluate weather the ribbon is hide/shown.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900