![]() |
commandbar scope
Hi,
Actually I have three sheet in my excel workbook & for every sheet I want to create different commandbars which have buttons. I have used following code for sheet1 to create commandbar buttons: private Office.CommandBar commandBar; private Office.CommandBarButton downloadButton; private Office.CommandBarButton uploadButton; private void Sheet1_Startup(object sender, System.EventArgs e) { this.Deactivate += new Microsoft.Office.Interop.Excel.DocEvents_Deactivat eEventHandler(Sheet1_Deactivate); this.ActivateEvent += new Microsoft.Office.Interop.Excel.DocEvents_ActivateE ventHandler(Sheet1_Activate); CheckForToolbar(); } private void Sheet1_Shutdown(object sender, System.EventArgs e) { this.Deactivate += new Microsoft.Office.Interop.Excel.DocEvents_Deactivat eEventHandler(Sheet1_Deactivate); try { commandBar = this.Application.CommandBars["TrimsBar"]; commandBar.Visible = false; } catch { } } void Sheet1_Activate() { CheckForToolbar(); } void Sheet1_Deactivate() { try { commandBar = this.Application.CommandBars["TrimsBar"]; commandBar.Visible = false; } catch { } } private void CheckForToolbar() { // Verify that the toolbar is not already present try { commandBar = this.Application.CommandBars["TrimsBar"]; commandBar.Visible = true; } catch { // Not present, so create a new one CreateToolbar(); } } private void CreateToolbar() { try { commandBar = Application.CommandBars.Add("TrimsBar", Office.MsoBarPosition.msoBarTop, false, true); // Word count button downloadButton = (Office.CommandBarButton)commandBar.Controls.Add(1 , missing, missing, missing, true); downloadButton.Style = Office.MsoButtonStyle.msoButtonCaption; downloadButton.Caption = "Select Trims"; downloadButton.Tag = "SelectTrims"; downloadButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(b tnSelectTrims_Click); // Words per paragraph button uploadButton = (Office.CommandBarButton)commandBar.Controls.Add(1 , missing, missing, missing, true); uploadButton.Style = Office.MsoButtonStyle.msoButtonCaption; uploadButton.Caption = "Upload"; uploadButton.Tag = "Upload"; uploadButton.BeginGroup = true; uploadButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(b tnUploadButton_Click); clearButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(b tnClearButton_Click); // Make the command bar visible (a new command bar is // not visible by default commandBar.Visible = true; } catch (Exception e) { MessageBox.Show(e.ToString(), "Initialize error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } In the same way I have placed all these code to every sheet with different name. As I start the excel application with sheet1 as start sheet, all commandbars for each sheets get shown. But as per my requirement I want that only commandbar specific to sheet1 should be visible as the application starts & when user click on sheet2, the command bar for sheet1 should get invisible & respected to sheet2 get shown. Same for all the sheet. Please assist me show that I can make it clear. Thank you |
All times are GMT +1. The time now is 07:33 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com