Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting excel to open in a window that is full screen STEVE THE PARTS GUY Excel Worksheet Functions 0 August 22nd 07 08:26 PM
The window opens in a smaller window not full sized window. Rachael Excel Discussion (Misc queries) 0 November 7th 06 09:04 PM
In Excel - how to delete new window created from window on tool ba Doug Excel Worksheet Functions 1 April 20th 06 09:22 PM
How do I undo the Excel, Window Menu, New Window command OLDFANG Excel Discussion (Misc queries) 2 March 17th 06 05:31 PM
Formatting of workbook window Candee[_16_] Excel Programming 3 December 18th 03 06:46 PM


All times are GMT +1. The time now is 04:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"