Have implemented this and would like to know if this can be just for the left mouse click and the right mouse click is still active as I would like to control the pivot chart options on the charts once enlarged.
here is the code :
Option Explicit
Public WithEvents objChart As Chart
Private Sub objChart_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
Dim strAltText As String
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets(objChart.Parent.Parent.Name)
strAltText = wks.Shapes(objChart.Parent.Name).AlternativeText
If strAltText = "" Then
Call ZoomChart(objChart.Parent)
Else
If Right(strAltText, 1) = "+" Then
Call ResetChartZoom(objChart.Parent)
Else
Call ZoomChart(objChart.Parent)
End If
End If
objChart.Parent.TopLeftCell.Select
Set wks = Nothing
End Sub
Sub ZoomChart(cht As ChartObject)
Call SetChartAltText(cht)
cht.Parent.Cells(1, 1).Select
With cht
.Left = ActiveWindow.VisibleRange.Cells(1, 1).Left
.Top = ActiveWindow.VisibleRange.Cells(1, 1).Top
.Height = ActiveWindow.VisibleRange.Columns(1).Resize(ActiveWindow.VisibleRange.Rows.Count - 1).Height
.Width = ActiveWindow.VisibleRange.Rows(1).Resize(, ActiveWindow.VisibleRange.Columns.Count - 1).Width
.BringToFront
End With
End Sub
Sub ResetChartZoom(cht As ChartObject)
Dim strAltText As String
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets(cht.Parent.Name)
strAltText = wks.Shapes(cht.Name).AlternativeText
strAltText = Replace(strAltText, "+", "-")
wks.Shapes(cht.Name).AlternativeText = strAltText
With cht
.Left = CInt(Split(strAltText, ";")(0))
.Top = CInt(Split(strAltText, ";")(1))
.Height = CInt(Split(strAltText, ";")(2))
.Width = CInt(Split(strAltText, ";")(3))
End With
Set wks = Nothing
End Sub
Sub SetChartAltText(cht As ChartObject)
Dim strAltText As String
Dim wks As Worksheet
Set wks = ThisWorkbook.Worksheets(objChart.Parent.Parent.Name)
strAltText = objChart.Parent.Left
strAltText = strAltText & ";" & objChart.Parent.Top
strAltText = strAltText & ";" & objChart.Parent.Height
strAltText = strAltText & ";" & objChart.Parent.Width
strAltText = strAltText & ";+"
wks.Shapes(cht.Name).AlternativeText = strAltText
Set wks = Nothing
End Sub