Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Friday, January 8, 2016

How to Know SHIFT/CTRL/ALT was pressed in VBA


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim str As String


Select Case Shift
Case 1
    str = "SHIFT was pressed."
Case 2
    str = "CTRL was pressed."
Case 3
    str = "SHIFT + CTRL was pressed."
Case 4
    str = "ALT was pressed."
Case 5
    str = "ALT + SHIFT was pressed."
Case 6
    str = "ALT + CTRL was pressed."
Case 7
    str = "ALT + SHIFT + CTRL was pressed."
End Select

Me.Label1 = str

End Sub




Download File











Wednesday, January 6, 2016

How to Know Right/Left/Middle Click on Command Button in VBA

a. First add a userform to a Workbook (right click VBE(Visual Basic Editor) > Insert > Userform)
b. Add a command button and a label


c. Right Click Command Button, and then click View Code
d. Then choose, Mouseup event


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim str As String


Select Case Button
Case 1
    str = "The left button was pressed."
Case 2
    str = "The right button was pressed."
Case 4
    str = "The middle button was pressed."
Case Else
    str = "The unknown button was pressed."
End Select

Me.Label1 = str

End Sub

The settings for Button are:



Download File