Chart MouseDownByVal Button As Long ByVal Shift As Long ByVal x As Long ByVal y As Long

Chart_MouseDown occurs when the cursor is over the chart and any mouse button is pressed. Button is the mouse button that was clicked; Shift is whether a Shift, Ctrl, or Alt key was pressed; X is the X coordinate of the cursor when the button is pressed; Y is the Y coordinate of the cursor when the button is pressed.

The following code zooms in on a left mouse click and zoom out on a right mouse click. Use the Cancel argument in the BeforeRightClick event to handle the menus that appear when right-clicking on a chart:

Private Sub Chart_MouseDown(ByVal Button As Long, ByVal Shift As Long, _

ByVal x As Long, ByVal y As Long) If Button = 1 Then

ActiveChart.Axes(xlValue).MaximumScale = _ ActiveChart.Axes(xlValue).MaximumScale - 50 End If

If Button = 2 Then

ActiveChart.Axes(xlValue).MaximumScale = _ ActiveChart.Axes(xlValue).MaximumScale + 50 End If End Sub

0 0

Post a comment