PDA

View Full Version : Solved: OWC Spreadsheet: Disable Right-Click menu



stanl
02-21-2006, 04:24 AM
I an displaying csv data in an OWC11 Spreadsheet control. I would like to either disable the default right-click menu or substitute my own. I tried .enableevents=False for the former but that does nothing. I also tried coding the MouseDown/MouseUp events which will bring up a custom menu, but immediately after the default menu appears. I read one post where either of these would have worked in earlier versions of OWC - so am I stuck?
TIA
Stan

Marcster
02-21-2006, 05:34 AM
Hi stanl,

See if this works:


Private Sub Spreadsheet1_Click(ByVal EventInfo As OWC.SpreadsheetEventInfo)
If EventInfo.Button = 2 Then '2=Right button
MsgBox "Right click menu invoked."
EventInfo.ReturnValue = False
End If
End Sub


You can also display a message or cancel any action on the menu by:


Private Sub Spreadsheet1_BeforeCommand(ByVal EventInfo As OWC.SpreadsheetEventInfo)

If EventInfo.Command = ssCopy Then
MsgBox "Copy is not allowed."
EventInfo.ReturnValue = False
End If

End Sub


Other commands:
ssCalculate
ssInsertRows
ssInsertColumns
ssDeleteRows
ssDeleteColumns
ssCut
ssCopy
ssPaste
ssExport
ssUndo
ssSortAscending
ssSortDescending
ssFind
ssClear
ssAutoFilter
ssProperties
ssHelp

HTH,

Marcster.

Bob Phillips
02-21-2006, 06:00 AM
I an displaying csv data in an OWC11 Spreadsheet control. I would like to either disable the default right-click menu or substitute my own. I tried .enableevents=False for the former but that does nothing. I also tried coding the MouseDown/MouseUp events which will bring up a custom menu, but immediately after the default menu appears. I read one post where either of these would have worked in earlier versions of OWC - so am I stuck?
TIA
Stan

Application.CommandBars("Cell").Enabled=False

stanl
02-21-2006, 06:57 AM
Application.CommandBars("Cell").Enabled=False


is for Excel not OWC. Marcster, I tried your suggestions, the default menu still pops up. I have attached a zip with the csv and a simple html page [just change the path to the csv file as hard-coded in the html] if you want to play.
Stan

Bob Phillips
02-21-2006, 07:36 AM
Application.CommandBars("Cell").Enabled=False


is for Excel not OWC.

Is this a response to me? If so, I don't get it.

Marcster
02-21-2006, 07:57 AM
stanl,

I'm still playing around with this. I haven't got OWC11.
Does this work: (it still displays the context menu on mine though :banghead: )


Private Sub Spreadsheet1_MouseDown(ByVal EventInfo As OWC.SpreadsheetEventInfo)
If EventInfo.Button = 2 Then
MsgBox "Right click menu invoked."
EventInfo.ReturnValue = False
End If
End Sub


xld,
Your code disables the right-click menu on a worksheet in Excel
not on OWC (Office Web Components).
You can add the OWC Spreadsheet ActiveX control to a userform or web page.

Marcster.

Marcster
02-21-2006, 08:24 AM
Shift+F10 also displays the right-click menu too.
So you need to disable that too.

stanl
02-21-2006, 08:43 AM
I have a sneaking suspicion the right-click context menu is related more to the window object not the spreadsheet - but there is no .hwnd property associated with the OWC spreadsheet, only for the OWC Pivot. In answer to your other post, I did try MouseUp, MouseDown and Click - all of which can identify the button as 2 [right click], bit the context menu still appears no matter what. Does your version of OWC accept .enableevents=False?

Stan

Marcster
02-21-2006, 09:22 AM
This works:

Private Sub Spreadsheet1_MouseDown(ByVal EventInfo As OWC.SpreadsheetEventInfo)


If EventInfo.Button = 2 Then
EventInfo.ReturnValue = False
MsgBox "Right click menu invoked."
End If

SendKeys "{ESC}"

End Sub


But you need to disable the Shift+F10 key press (still working on this bit), as this invokes the menu too.

HTH,

Marcster.

Marcster
02-21-2006, 09:42 AM
This works for me:


Option Explicit
Dim btnShift As Boolean
Private Sub Spreadsheet1_KeyDown(ByVal EventInfo As OWC.SpreadsheetEventInfo)
If EventInfo.KeyCode = 16 Then '16 Shift, 121 F10
btnShift = True
End If
If btnShift = True And EventInfo.KeyCode = 121 Then
MsgBox "Short-cut menu disabled."
SendKeys "{ESC}"
btnShift = False
End If
End Sub
Private Sub Spreadsheet1_MouseDown(ByVal EventInfo As OWC.SpreadsheetEventInfo)
If EventInfo.Button = 2 Then
EventInfo.ReturnValue = False
MsgBox "Short-cut menu disabled."
End If
SendKeys "{ESC}"
End Sub


Marcster.

stanl
02-21-2006, 10:03 AM
Is there a way to fit that code into the htm file I posted as part of the zip. Once of the reasons I am using OWC is because Excel will not be available for some users. Thanks:bow: Stan

Marcster
02-21-2006, 11:28 AM
...which will bring up a custom menu, but immediately after the default menu appears.
Have you got the code to display a custom shortcut menu?.
If so you could just add some code that acts like pressing the Esc key
with SendKeys. So it will dismiss the short-cut menu.

Maybe something like:
Dim WSH_Shell
Set WSH_Shell.CreateObject("WScript.Shell)
WSH_Shell.SendKeys "{ESC}"

Might work. I haven't tried it though.

Do you want to disable the short-cut menu when you right-click on a web page?.
Or just when you right-click on the OWC Spreadsheet?.

Marcster.

stanl
02-21-2006, 01:11 PM
Well, wouldn't you know I just stumbled upon the BeforeContextMenu Event - set the 4th parm to True and all is well. Thanks again for all your efforts and code snippets.

P.S. I think you can also use this event to substitute your own context menu which is what I really am after.



This example displays a custom context menu. The menu contains four options, the last option displays a submenu.

Sub Spreadsheet1_BeforeContextMenu(x, y, Menu, Cancel) Dim cmContextMenu(4) Dim cmClearSubMenu(2) cmClearSubMenu(0) = Array("&All", "ClearAll") cmClearSubMenu(1) = Array("&Formats", "ClearFormats") cmClearSubMenu(2) = Array("&Values", "ClearValues") cmContextMenu(0) = Array("Cu&t", "owc2") cmContextMenu(1) = Array("&Copy", "owc3") cmContextMenu(2) = Array("&Paste", "owc4") cmContextMenu(3) = Empty cmContextMenu(4) = Array("Clea&r", cmClearSubMenu) Menu.Value = cmContextMenuEnd Sub

Stan

Marcster
02-22-2006, 02:13 AM
Hi stanl,
Glad you've solved this problem :thumb.


BeforeContextMenu isn't in my version of OWC. I'm using Office 2000.
BeforeContextMenu is in Office 2003.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/owcvba11/html/ocevtBeforeContextMenu_HV03082982.asp


Marcster.

stanl
02-22-2006, 05:49 AM
Hi stanl,
BeforeContextMenu isn't in my version of OWC. I'm using Office 2000.
BeforeContextMenu is in Office 2003.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/owcvba11/html/ocevtBeforeContextMenu_HV03082982.asp


Marcster.

Which begs the question: are they making OWC better or more arcane:doh:

Stan