Sub Chart1_Click()
ZoomChartInAndOut ActiveSheet.ChartObjects(Application.Caller)
End Sub
Sub Chart2_Click()
ZoomChartInAndOut ActiveSheet.ChartObjects(Application.Caller)
End Sub
Sub Chart3_Click()
ZoomChartInAndOut ActiveSheet.ChartObjects(Application.Caller)
End Sub
Public strObjNames As String
Sub ZoomChartInAndOut(ByRef ChartToZoomInAndOut As ChartObject, Optional ByVal blnShowShapes As Boolean = 0)
'// Author : Krishnakumar @ ExcelFox.com
'// Created on : 23-Mar-2011
'// Purpose : Resize Chart
Dim blnZoomIn As Boolean
Dim lngBlnPos As Long
Dim lngLoop As Long
Dim rngVisible As Range
Dim objObject As Object
Dim shpChart As Shape
Dim strTemp As String
Dim strAltText As String
Dim strShp As String
Dim OldCSFS As String
Dim OldCAFS As Single
Dim NewCAFS As Single
Dim OldCTFS As Single
Dim NewCTFS As Single
Dim NewCSFS() As Single
Dim SplitText As Variant
Dim SplitAddr As Variant
Dim SplitCSFS As Variant
Dim strNewCSFS As String
Dim strSAold As String
Dim strVsblRngAddr As String
Dim ChtAreaOldColor As Long
Dim objCount As Long
Dim objLoop As Long
Dim blnLegend As Boolean
Dim NoColor As Long
Const ZoomInChartAreaFontSize As Long = 20
Const ZoomInWidthAdjustment As Long = 35
Const ZoomInHeightAdjustment As Long = 10
Const ZoomInShapeFontSize As Long = 20
Const ZoomInChartAreaColor As Long = 16777215
Set rngVisible = ActiveWindow.VisibleRange
strVsblRngAddr = rngVisible.Address
With ChartToZoomInAndOut
If .Parent.ProtectContents Then
MsgBox "'" & UCase$(.Parent.Name) & "' is protected. Unprotect the sheet and try again", 64, "ExcelFox.com"
Exit Sub
End If
End With
On Error GoTo QuickExit
If Len(ChartToZoomInAndOut.ShapeRange.AlternativeText) = 0 Then
With ChartToZoomInAndOut
strTemp = CSng(.Left) & ":" & CSng(.Width) & ":" & CSng(.Top) & ":" & CSng(.Height) & "|TRUE"
strTemp = strTemp & vbLf & "CA FS=" & .Chart.ChartArea.Font.Size & Space(10)
If .Chart.HasTitle Then strTemp = strTemp & vbLf & "CT FS=" & .Chart.ChartTitle.Font.Size & Space(10)
If .Chart.Shapes.Count Then
strShp = "CS FS="
For Each shpChart In .Chart.Shapes
strShp = strShp & ";" & shpChart.TextFrame.Characters.Font.Size
Next
strShp = Replace(strShp, "=;", "=") & Space(50)
strTemp = strTemp & vbLf & strShp
End If
strSAold = .Parent.ScrollArea
strTemp = strTemp & vbLf & "AS SA=" & IIf(Len(strSAold), strSAold & Space(20), "Nill" & Space(20))
ChtAreaOldColor = ChartToZoomInAndOut.Chart.ChartArea.Interior.Color
strTemp = strTemp & vbLf & "CA FC=" & ChtAreaOldColor & Space(10)
strTemp = strTemp & vbLf & " © Krishnakumar @ ExcelFox.com"
.ShapeRange.AlternativeText = strTemp
End With
End If
strAltText = ChartToZoomInAndOut.ShapeRange.AlternativeText
blnZoomIn = InStr(1, strAltText, "TRUE")
lngBlnPos = InStr(1, strAltText, "|")
SplitAddr = Split(rngVisible.Address, ":")
With ChartToZoomInAndOut.Chart
NewCAFS = .ChartArea.Font.Size
If .HasTitle Then NewCTFS = .ChartTitle.Font.Size
If .Shapes.Count Then
For lngLoop = 1 To .Shapes.Count
ReDim Preserve NewCSFS(1 To lngLoop)
NewCSFS(lngLoop) = CSng(.Shapes(lngLoop).TextFrame.Characters.Font.Size)
Next
End If
Application.GoTo .Parent.TopLeftCell
End With
If blnZoomIn Then
With ChartToZoomInAndOut
.Chart.ChartArea.Font.Size = ZoomInChartAreaFontSize
.Left = Range(SplitAddr(0)).Left + 1
.Width = rngVisible.Columns.Width - ZoomInWidthAdjustment
.Top = Range(SplitAddr(0)).Top + 1
.Height = rngVisible.Rows.Height - ZoomInHeightAdjustment
.ShapeRange.AlternativeText = Replace(strAltText, "TRUE", "FALSE")
If Not .BringToFront Then .BringToFront
.Parent.ScrollArea = vbNullString
.Parent.ScrollArea = strVsblRngAddr
End With
strAltText = ChartToZoomInAndOut.ShapeRange.AlternativeText
If ChartToZoomInAndOut.Chart.ChartArea.Interior.Color = -2 Then
ChartToZoomInAndOut.Chart.ChartArea.Interior.Color = ZoomInChartAreaColor
End If
OldCAFS = CSng(Trim$(Mid$(strAltText, InStr(1, strAltText, "CA FS=") + 6, 10)))
If OldCAFS <> NewCAFS Then _
strAltText = Replace(strAltText, "CA FS=" & OldCAFS, "CA FS=" & NewCAFS)
If InStr(1, strAltText, "CT FS=") Then
OldCTFS = CSng(Trim(Mid$(strAltText, InStr(1, strAltText, "CT FS=") + 6, 10)))
If OldCTFS <> NewCTFS Then _
strAltText = Replace(strAltText, "CT FS=" & OldCTFS, "CT FS=" & NewCTFS)
End If
If InStr(1, strAltText, "CS FS=") Then
OldCSFS = Trim(Mid$(strAltText, InStr(1, strAltText, "CS FS=") + 6, 50))
SplitCSFS = Split(OldCSFS, ";")
For lngLoop = 1 To ChartToZoomInAndOut.Chart.Shapes.Count
If lngLoop <= 1 + UBound(SplitCSFS) Then
If SplitCSFS(lngLoop - 1) <> NewCSFS(lngLoop) Then
strNewCSFS = strNewCSFS & ";" & NewCSFS(lngLoop)
Else
strNewCSFS = strNewCSFS & ";" & NewCSFS(lngLoop)
End If
Else
strNewCSFS = strNewCSFS & ";" & NewCSFS(lngLoop)
End If
ChartToZoomInAndOut.Chart.Shapes(lngLoop).TextFrame.Characters.Font.Size = ZoomInShapeFontSize
Next
If Len(strNewCSFS) > 1 Then strNewCSFS = Mid$(strNewCSFS, 2)
strAltText = Replace(strAltText, "CS FS=" & OldCSFS, "CS FS=" & strNewCSFS)
End If
ChartToZoomInAndOut.ShapeRange.AlternativeText = strAltText
If Not blnShowShapes Then
strObjNames = ""
For Each objObject In ActiveSheet.Shapes
If objObject.Visible Then strObjNames = strObjNames & "|" & objObject.Name
Select Case objObject.Type
Case 3
Case 8
If objObject.FormControlType <> 7 Then objObject.Visible = 0
Case Else
objObject.Visible = 0
End Select
Next
End If
Else
SplitText = Split(Split(strAltText, "|")(0), ":")
With ChartToZoomInAndOut
.Left = SplitText(0)
.Width = SplitText(1)
.Top = SplitText(2)
.Height = SplitText(3)
.ShapeRange.AlternativeText = Replace(strAltText, "FALSE", "TRUE")
If Not .SendToBack Then .SendToBack
strAltText = ChartToZoomInAndOut.ShapeRange.AlternativeText
.Chart.ChartArea.Font.Size = CSng(Trim(Mid$(strAltText, InStr(1, strAltText, "CA FS=") + 6, 10)))
.Chart.ChartArea.Interior.Color = CLng(Trim(Mid$(strAltText, InStr(1, strAltText, "CA FC=") + 6, 10)))
If .Chart.HasTitle Then .Chart.ChartTitle.Font.Size = CSng(Trim(Mid$(strAltText, InStr(1, strAltText, "CT FS=") + 6, 10)))
If .Chart.Shapes.Count Then
If InStr(1, strAltText, "CS FS=") Then
OldCSFS = Trim(Mid$(strAltText, InStr(1, strAltText, "CS FS=") + 6, 50))
SplitCSFS = Split(OldCSFS, ";")
For lngLoop = 0 To UBound(SplitCSFS)
.Chart.Shapes(lngLoop + 1).TextFrame.Characters.Font.Size = CSng(SplitCSFS(lngLoop))
Next
End If
End If
strSAold = Trim(Mid$(strAltText, InStr(1, strAltText, "AS SA=") + 6, 50))
strSAold = Trim$(Left$(strSAold, InStr(1, strSAold & Chr(32), Chr(32))))
If strSAold <> "Nill" Then
.Parent.ScrollArea = strSAold
Else
.Parent.ScrollArea = ""
End If
.ShapeRange.AlternativeText = ""
End With
For Each objObject In ActiveSheet.Shapes
If InStr(1, strObjNames, objObject.Name) Then objObject.Visible = 1
Next
End If
QuickExit:
If Err.Number <> 0 Then
MsgBox "Error #" & Err.Number & vbLf & Err.Description, 64, "ExcelFox.com"
ChartToZoomInAndOut.ShapeRange.AlternativeText = ""
Err.Clear: On Error GoTo 0
End If
End Sub