Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Custum Excel RMB Context Menu
Hi Nick,
It seems to be hard to implement it via the winform context menu. I think we would better do it by change the default cell contextmenu, i.e. the menu which will be shown when we right click on the sheet. Here goes the code snippet. <Code snippet public ContextMenu m_RMBContextMenu = null; Excel.Application exApp=null; Microsoft.Office.Core.CommandBarButton cbb=null; Microsoft.Office.Core.CommandBar t=null; public void NewWorkbook(Excel.Workbook Wb) { System.Diagnostics.Debug.WriteLine("NewWorkbook"); exApp = Wb.Application; object type = 1; object oMissing = System.Reflection.Missing.Value; //find the cell menu and then disable all and then add the ones we want int cnt = (int)exApp.CommandBars.GetType().InvokeMember("Cou nt",System.Reflection.Bind ingFlags.GetProperty,null,exApp.CommandBars,new object[]{}); for( int i =1 ;i<=cnt;i++) { t = (Microsoft.Office.Core.CommandBar)exApp.GetType(). InvokeMember("CommandBars" ,System.Reflection.BindingFlags.GetProperty,null,e xApp,new object[]{i}); if (t.Name == "Cell") { t.Reset(); for(int j =1;j<=t.Controls.Count;j++) t.Controls[j].Visible = false; cbb = (Microsoft.Office.Core.CommandBarButton)t.Controls .Add(type,oMissing,oMissin g,oMissing,oMissing); break; } } cbb.Caption = "Hello"; cbb.Click+=new Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler(cbb_Click); } private void cbb_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault) { Console.WriteLine("cbb_Click"); } public void WorkbookBeforeClose(Excel.Workbook Wb, ref bool Cancel) { t.Reset(); //reset the menu System.Diagnostics.Debug.WriteLine("WorkbookBefore Close"); } <Code snippet Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Adding commands to the Excel 2007 Chart context menu | Charts and Charting in Excel | |||
Excel 2003 Context menu handle | Excel Discussion (Misc queries) | |||
Updating context menu in Excel | Excel Discussion (Misc queries) | |||
Add items to context menu | Excel Worksheet Functions | |||
context menu | Excel Programming |