Formatting the excel window

Hi,

I am opening an excel file within a windows form. I want the user to only play around with the excel area. The user should not create or open an excel file. So I want to hide the menu bar and disable the New and Open standard toolbar buttons. I use the following C# code to achieve my goal:

Code Snippet

// xlApp is the instance of Excel.Application

xlApp.WindowState = Excel.XlWindowState.xlMaximized;

// Hide the Menu bar

int counter = xlApp.ActiveWindow.Application.CommandBars.Count;

for (int i = 1; i <= counter; i++)

{

try

{

string nm = xlApp.ActiveWindow.Application.CommandBars[i].Name;

if (nm =="Standard")

{

int count_control = xlApp.ActiveWindow.Application.CommandBars[i].Controls.Count;

for (int j = 1; j <= 2; j++)

{

xlApp.ActiveWindow.Application.CommandBars[i].Controls[j].Enabled =false;

}

}

if (nm =="Worksheet Menu Bar")

{

xlApp.ActiveWindow.Application.CommandBars[i].Enabled =false;

}

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

}

// Show the necessary command bars

xlApp.CommandBars["Standard"].Visible =true;

xlApp.CommandBars["Standard"].Position = Office.MsoBarPosition.msoBarTop;

xlApp.CommandBars["Visual Basic"].Visible =true;

xlApp.CommandBars["Visual Basic"].Position = Office.MsoBarPosition.msoBarTop;

xlApp.CommandBars["Formatting"].Visible =true;

xlApp.CommandBars["Formatting"].Position = Office.MsoBarPosition.msoBarTop;

The problem now is that at times this code works fine and I see only the necessary buttons and toolbars but at times I dont see any toolbar button. Can somebody please explain this strange behaviour? Is there a standard code to hide/show excel buttons/toolbars?

(I am using C# with Office 2000)

Regards,

Asim.

[4140 byte] By [AsimPatnaik] at [2008-1-9]
# 1

Hi Asim,

Your issue is off topic here. This is a forum target at VSTO development. So the right place for your question should be Excel News Group. Try to ask there. I think experts there will have a quick idea about your scenario.

http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.excel.programming&lang=en&cr=US

Thanks

Ji

JiZhou–MSFT at 2007-10-3 > top of Msdn Tech,Feedback for forums and MSDN websites,Off-Topic Posts (Do Not Post Here)...