BeforeContextMenu Event

Microsoft Office Web Components Object Model

BeforeContextMenu Event

       

Occurs before a context menu is to be shown. A context menu is shown when the user right-clicks or they press the Application key.

Private Sub Object_BeforeContextMenu(ByVal x As Long, ByVal y As Long, ByVal Menu As Byref, ByVal Cancel As ByRef)

Represents the x-coordinate where the context menu is to appear.

y  Represents the y-coordinate where the context menu is to appear.

Menu  Set the Value property of this object to an array that contains the menu items to display.

Cancel  Set the Value property of this object to True to cancel the keystroke.

Remarks

Use this event to customize the context menus in the Microsoft Office Web Components.

Example

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 = cmContextMenu

End Sub