Consulting

Results 1 to 15 of 15

Thread: Solved: OWC Spreadsheet: Disable Right-Click menu

  1. #1
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location

    Solved: OWC Spreadsheet: Disable Right-Click menu

    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

  2. #2
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Hi stanl,

    See if this works:

    [VBA]
    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
    [/VBA]

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

    [VBA]
    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
    [/VBA]

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

    HTH,

    Marcster.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by stanl
    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

  4. #4
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by stanl
    Application.CommandBars("Cell").Enabled=False
    is for Excel not OWC.
    Is this a response to me? If so, I don't get it.

  6. #6
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    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 )

    [VBA]
    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
    [/VBA]

    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.

  7. #7
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Shift+F10 also displays the right-click menu too.
    So you need to disable that too.

  8. #8
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

  9. #9
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    This works:
    [VBA]
    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
    [/VBA]

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

    HTH,

    Marcster.

  10. #10
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    This works for me:

    [VBA]
    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
    [/VBA]

    Marcster.

  11. #11
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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 Stan

  12. #12
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    ...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:
    [VBA] Dim WSH_Shell
    Set WSH_Shell.CreateObject("WScript.Shell)
    WSH_Shell.SendKeys "{ESC}"
    [/VBA]
    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.

  13. #13
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    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

  14. #14
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Hi stanl,
    Glad you've solved this problem .


    BeforeContextMenu isn't in my version of OWC. I'm using Office 2000.
    BeforeContextMenu is in Office 2003.
    http://msdn.microsoft.com/library/de...HV03082982.asp


    Marcster.

  15. #15
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Marcster
    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/de...HV03082982.asp


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

    Stan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •