After you select View Code
, you are taken directly into the VBE (Visual Basic Editor) where you can start entering the event procedure code:
Chart_MouseDown
Syntax: Chart_MouseDown(Button, Shift, X, Y)
The Chart_MouseDown
event procedure runs when a mouse button is pressed while the pointer is over a chart. This procedure has four arguments:
Button
Determines which mouse button was pressed:- The
xlPrimaryButton
constant represent the left button (or primary mouse button) - The
xlSecondaryButton
constant represents the right button (or secondary mouse button) - You also can use the numeric values to determine which mouse button was press, for example, value
1
for left button,2
for right button, and3
for middle button
- The
Shift
Specifies the state of theShift
,Ctrl
, andAlt
keys:- Value
0
– Not any key selected - Value
1
–Shift
was selected - Value
2
–Ctrl
was selected - Value
4
–Alt
was selected
- Value
X
Specify thex
coordinates of the mouse pointer.Y
Specify they
coordinates of the mouse pointer.
1. Chart MouseDown Event Example:
Private Sub Chart_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long) If Button = 1 And Shift = 1 Then MsgBox "Primary mouse button down, shift key pressed on x:" & X & " y:" & Y End If End Sub
2. Chart_MouseDown Event Procedure Complete Example:
Private Sub Chart_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long) Dim sft As String Dim btn As String Select Case (Shift) Case 0 sft = "none" Case 1 sft = "Shift" Case 2 sft = "Ctrl" Case 4 sft = "Alt" Case Else sft = Shift & "" End Select Select Case (Button) Case xlPrimaryButton btn = "primary" Case xlSecondaryButton btn = "secondary" Case Else btn = Button & "" End Select MsgBox "Mouse " & btn & " button down, " & sft & " key pressed, x:" & X & " y:" & Y End Sub
Chart_MouseMove
Syntax: Chart_MouseMove(Button, Shift, X , Y)
The Chart_MouseMove
event procedure runs when the position of a mouse pointer changes over a chart.
Chart MouseMove Event Example:
Private Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long) If Button = 1 And Shift = 1 Then MsgBox "Primary mouse button MOVE, shift key pressed on x:" & X & " y:" & Y End If End Sub
Chart_MouseUp
Syntax: Chart_MouseUp(Button, Shift, X , Y)
The Chart_MouseUp
event procedure runs when a mouse button is released while the pointer is over a chart.
Chart MouseUp Event Example:
Private Sub Chart_MouseUp(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long) If Button = 1 And Shift = 1 Then MsgBox "Primary mouse button UP, shift key pressed on x:" & X & " y:" & Y End If End Sub