Microsoft Office Tutorials and References
In Depth Information
ADD A RIGHT-CLICK MENU TO A USER FORM
the Alt key. If someone holds down multiple keys, Excel adds the values (for
example, 5 indicates Alt+Shift). Here is the complete table of possible values
for the Shift variable:
Shift Value
Meaning
0
No keys
1
Shift
2
Ctrl
Part
3
3
Shift+Ctrl
4
Alt
5
Shift+Alt
6
Ctrl+Alt
7
Shift+Ctrl+Alt
The event handler macro fi rst makes sure that Button is 2 and Shift is 0 .
The macro uses API calls to build a menu. You can customize the menu by
adding additional options to the menu, using:
AppendMenu hMenu, MF_STRING, 1, "Menu Text Here"
In this case, the 1 indicates the value returned to the macro if that menu item
is selected.
The TrackPopupMenu function displays the menu and determines which
item is selected by the person using the form. The selection is returned to the
variable ret . After this line of code, the ret variable indicates the numeric
menu value selected.
Later in the macro, a Case Select handles the possible menu choices and
calls an appropriate procedure for each.
Place all this code in the code pane for the user form:
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function CreatePopupMenu Lib "user32" () As Long
Private Declare Function TrackPopupMenuEx Lib "user32" _
(ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long,
ByVal Y As Long, _
ByVal hWnd As Long, ByVal lptpm As Any) As Long
Search JabSto ::




Custom Search