Search code examples
excelvbabar-chartpowerpointaxis-labels

Resize Plot Area dynamically to see truncated text in Category Axis of a Clustered Bar Chart


I am copying and pasting Clustered Bar charts from a Workbook into a Powerpoint deck created dynamically. The Bar charts Category Axis may have long text (Axis labels), that sometimes gets truncated. The Wrap text option for Category Axis is greyed out. So i want to move the Plot Area of the Chart to the Right dynamically to make the Category Axis truncated text visible.

enter image description here

Sub ExportClusteredBarChartsToPowerpoint()
    Dim oPPT As Object: Set oPPT = CreateObject("PowerPoint.Application")
    With oPPT
        .Visible = True
        .Activate
    End With

    Dim oPres As Object: Set oPres = oPPT.presentations.Add
    Dim oSlide As Object
    Dim iNdx As Integer
    Dim oChart As ChartObject
    Dim oWS As Worksheet: Set oWS = ThisWorkbook.Sheets("ChartsSheet")

    iNdx = 1
    With oWS
        For Each oChart In oWS.ChartObjects

            oChart.Chart.ChartArea.Copy

            Set oSlide = oPres.slides.Add(iNdx, 12)       'ppLayoutBlank
            oSlide.Shapes.PasteSpecial 0, msoFalse           '0=ppPasteDefault
            Application.CutCopyMode = False

            With oSlide.Shapes(1)
                .ScaleWidth 1.75, 0, 1 'msoTrue, msoScaleFromMiddle
                .ScaleHeight 1.75, 0, 1 'msoTrue,msoScaleFromMiddle
                oPPT.Windows(1).View.ZoomToFit = False
                oPPT.Windows(1).View.Zoom = 98
            End With
            iNdx = iNdx + 1
        Next oChart
    End With    
End Sub

Is this possible or is there an alternative solution using VBA?


Solution

  • This will expand the left axis area by 50 points every time you run it:

    With oSlide.Shapes(1)
      If .HasChart Then
        With .Chart.PlotArea
          .Width = .Width - 50
          .Left = .Left + 50
        End With
      End If
    End With