Microsoft Office Tutorials and References
In Depth Information
ADD A RIGHT-CLICK MENU TO A USER FORM
The lines inside the With block assign the Top property for the button to be
the same as the Top property for the cell at the top-left corner of the visible
As you scroll through the worksheet, the button stays at the top of the window
(Figures 144 and 145).
Figure 144. If you scroll down, the but on moves.
Figure 145. h e but on moves as you scroll
through the worksheet.
Summary: You can use a macro to keep a button visible in a worksheet.
ADD A RIGHT-CLICK MENU
TO A USER FORM
Challenge: You’ve designed a custom user form. You want to add a right-click
menu (also called a context menu) to it.
Solution: Many people are used to right-clicking in Excel. If you’ve designed
a custom user form, people might want to right-click the form to get additional
options. A solution Haluk posted at the MrExcel message board takes advantage
of the user form’s MouseDown event. This event is run when someone clicks
on the user form. A variable called Button indicates whether the left or right
mouse button is clicked. Another variable, Shift , indicates which combinations
of the Shift, Ctrl, and Alt keys are held down.
For the Button variable, 1 indicates a left-click, and 2 indicates a right-click.
For the Shift variable, 0 indicates that no keys are used in combination with the
mouse click, 1 indicates the Shift key, 2 indicates the Ctrl key, and 4 indicates