【问题标题】:vba Excel 2010 - MouseDown event on Active X Controls Command Buttonvba Excel 2010 - Active X 控件命令按钮上的 MouseDown 事件
【发布时间】:2015-09-10 07:32:25
【问题描述】:

this page 微软解释了如何知道当 MouseDown 事件发生时是否按下了 Shift、Ctrl 和 Alt 的组合:

Private Sub Form_MouseDown(Button As Integer, _ Shift As Integer, X As Single, Y As Single) ShiftTest = Shift And 7 Select Case ShiftTest Case 1 ' or vbShiftMask Print "You pressed the SHIFT key." Case 2 ' or vbCtrlMask Print "You pressed the CTRL key." Case 4 ' or vbAltMask Print "You pressed the ALT key." Case 3 Print "You pressed both SHIFT and CTRL." Case 5 Print "You pressed both SHIFT and ALT." Case 6 Print "You pressed both CTRL and ALT." Case 7 Print "You pressed SHIFT, CTRL, and ALT." End Select End Sub

它工作得很好。我有很多命令按钮,是否可以不复制粘贴所有这些行并用一个名为的函数替换它们?

这是一个想法,但它不起作用:

Private Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) call test(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) End Sub

Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) call test(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) End Sub

CommandButton3 和 4 相同...

Private Sub test(Button As Integer, _ Shift As Integer, X As Single, Y As Single) ShiftTest = Shift And 7 Select Case ShiftTest Case 1 ' or vbShiftMask Print "You pressed the SHIFT key." Case 2 ' or vbCtrlMask Print "You pressed the CTRL key." Case 4 ' or vbAltMask Print "You pressed the ALT key." Case 3 Print "You pressed both SHIFT and CTRL." Case 5 Print "You pressed both SHIFT and ALT." Case 6 Print "You pressed both CTRL and ALT." Case 7 Print "You pressed SHIFT, CTRL, and ALT." End Select End Sub

【问题讨论】:

    标签: excel vba function events mousedown


    【解决方案1】:
    Private Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        test CommandButton1, Shift, X, Y
    End Sub
    
    Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        test CommandButton2, Shift, X, Y
    End Sub
    

    【讨论】:

    • 完美!谢谢弗朗索瓦
    猜你喜欢
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    • 2014-03-28
    • 2015-06-11
    • 2019-05-01
    相关资源
    最近更新 更多