View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Cannot seem to Cancel EXCEL App Right Click Event using C#

I think you're speaking the Greek here!

But I can disable the rightclick option on a worksheet by disabling the "Cell"
commandbar.

Maybe it'll work for you:

Dim myIndex As Long
myIndex = Application.CommandBars("cell").Index
Application.CommandBars(myIndex).Enabled = False
Application.CommandBars(myIndex + 3).Enabled = False

The +3 refers to the "cell" commandbar when you're in View|PageBreak Preview
mode.

(Don't forget to turn it back to True when you're done. This setting will be
kept the next time excel opens!)

Nick Biggs wrote:

I am trying to use Excel from C# and need to disable the menu that appears when clicking the right mouse button on a cell.

I am trying to do this using the Excel.AppEvents_SheetBeforeRightClickEventHandler from my C# WinForm application.

I have a MessageBox that pops up that proves my event handler actually fires via my delegate but after setting the "Cancel" variable to "true" it has no effect for me. The Excel RMB menu appears when it should not. The Cancel parameter is declared as "ref bool".

I am wondering if there is a problem with the marshalling of this variable in the Office PIA which I am using. I would be happy to send code that demos my problem. Can someone please let me know if they can make it work ?

By the way I have already written some VB6 code that works fine and VBA code in an Excel Workbook that also works just fine as well. Both disable the menu as I require when I set "Cancel" to "True". The problem is that I need to do this from a C# application.

Can anyone shed some light on this at all ?

I am using...

Microsoft Excel 2002 (10.4302.4219) SP-2
Visual Studio 2003 v7.1.3088
Microsoft .NET Framework 1.1 v1.1.4322

I obtained the Office XP Primary Interop Assemblies from the following link

http://www.microsoft.com/downloads/d...displaylang=en


--

Dave Peterson