Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Dear All,

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

i'm trying to hide ribbon display but its not hiding the ribbon.

What I have tried:

C#
public static bool ChangeRibbonDisplay(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);

               excelApplication.ExecuteExcel4Macro("show.toolbar(\"ribbon\"," + display + ")");

               excelWorkbook.Save();
               excelWorkbook.Close(true);

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


But, the above is not hiding the ribbon.

Even i have tried this:
excelApplication.SendKeys("^{F1}");//not hide/show


can anyone please help me.


Thanks in advance
Posted
Updated 5-Jun-17 7:11am
v2

1 solution

Check this: VBA auto hide ribbon in Excel 2013 - Stack Overflow[^]

A C# form may look like:
C#
excelApplication.CommandBars.ExecuteMso "HideRibbon"


[EDIT]
"HideRibbon" is the name of ribbon you have to change.

To get list of IdMso, please see: Ribbon Examples files and Tips[^]
 
Share this answer
 
v2
Comments
abdul subhan mohammed 6-Jun-17 3:16am    
Maciej, I have tried your code:
excelApplication.CommandBars.ExecuteMso("HideRibbon");
But still its not hiding the ribbon.
Maciej Los 6-Jun-17 8:46am    
HideRibbon is the name of ribbon you have to change.

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