Formatting the excel window

A

Asim

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.Name;

if (nm == "Standard")

{

int count_control =
xlApp.ActiveWindow.Application.CommandBars.Controls.Count;

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

{

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

}

}

if (nm == "Worksheet Menu Bar")

{

xlApp.ActiveWindow.Application.CommandBars.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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top