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

 
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
Name scope within a workbook Christer Excel Discussion (Misc queries) 0 March 24th 10 10:32 PM
Name Scope Slim Slender[_2_] Excel Worksheet Functions 2 December 16th 09 01:38 AM
Scope of name Slim Slender Excel Discussion (Misc queries) 0 December 13th 09 10:01 PM
Range Name Scope Gee Excel Discussion (Misc queries) 4 September 22nd 09 01:32 PM
VBAProject Scope Frank Kabel Excel Programming 0 July 15th 04 10:30 PM


All times are GMT +1. The time now is 02:57 PM.

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

About Us

"It's about Microsoft Excel"