动态调整绘图区域的大小以查看簇状条形图的类别轴中的截断文本

问题描述 投票:0回答:1

我正在将Clustered Bar charts中的Workbook复制并粘贴到动态创建的Powerpoint deck中。条形图的“类别轴”可能有长文本(“轴”标签),有时会被截断。类别轴的Wrap text选项为greyed out。所以我想移动Plot Area of the Chart to the Right dynamically以使类别轴截断的文本可见。

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

这是否可能,或者是否有使用VBA的替代解决方案?

excel vba bar-chart powerpoint-vba axis-labels
1个回答
0
投票

每次运行都会将左轴区域扩大50点:

With oSlide.Shapes(1)
  If .HasChart Then
    With .Chart.PlotArea
      .Width = .Width - 50
      .Left = .Left + 50
    End With
  End If
End With
© www.soinside.com 2019 - 2024. All rights reserved.