Powerpoint VBA - 调整图表和坐标轴标题的位置
Powerpoint VBA - adjust positions of chart and axis titles
我有以下代码:
Sub StandardiseChart(ByVal control As IRibbonControl)
Dim activeShape As Shape
'Determine Which Shape is Active
If ActiveWindow.Selection.Type = ppSelectionShapes Then
'Loop in case multiples shapes selected
Dim shp As Shape
For Each shp In ActiveWindow.Selection.ShapeRange
Set activeShape = shp ' First shape selected
Exit For
Next
'Now, reformat the selected shape if it is a chart
With activeShape
If .HasChart Then
' Chart title
.Chart.HasTitle = True
With .Chart.ChartTitle
.Left = 0
.Top = 0
End With
' Y axis
With .Chart.Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Text = "Placeholder"
.AxisTitle.Left = 0
.AxisTitle.Top = 20
.AxisTitle.Orientation = 0
End With
' Plot Area
With .Chart.PlotArea
.Left = 10
.Top = 50
End With
End If
End With ' activeShape
End If
End Sub
我希望它做三件事:
- 将图表标题固定到整个图表的左上角object(这看起来不错)
- 设置 y-axis 标题,使其与图表标题之间有 space 的 20pt(看起来也不错)
- 在绘图区域和 y-axis 标题之间再创建 50pt space(不好)。
无论我做什么(我尝试将数字调整为 70 而不是 50,甚至更大),我似乎都无法通过调整 space 来实现 (3)。具体来说,无论我做什么,绘图区域都不会移动。
我做错了什么?
如果在Chart.Plotarea末尾加一个点,就可以看到方法列表。在你的情况下,你正在寻找 .InsideLeft 和 .InsideTop,因为你想调整图表区域的内部距离:
With .Chart.PlotArea
.InsideLeft = 70
.InsideTop = 70
End With
我有以下代码:
Sub StandardiseChart(ByVal control As IRibbonControl)
Dim activeShape As Shape
'Determine Which Shape is Active
If ActiveWindow.Selection.Type = ppSelectionShapes Then
'Loop in case multiples shapes selected
Dim shp As Shape
For Each shp In ActiveWindow.Selection.ShapeRange
Set activeShape = shp ' First shape selected
Exit For
Next
'Now, reformat the selected shape if it is a chart
With activeShape
If .HasChart Then
' Chart title
.Chart.HasTitle = True
With .Chart.ChartTitle
.Left = 0
.Top = 0
End With
' Y axis
With .Chart.Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Text = "Placeholder"
.AxisTitle.Left = 0
.AxisTitle.Top = 20
.AxisTitle.Orientation = 0
End With
' Plot Area
With .Chart.PlotArea
.Left = 10
.Top = 50
End With
End If
End With ' activeShape
End If
End Sub
我希望它做三件事:
- 将图表标题固定到整个图表的左上角object(这看起来不错)
- 设置 y-axis 标题,使其与图表标题之间有 space 的 20pt(看起来也不错)
- 在绘图区域和 y-axis 标题之间再创建 50pt space(不好)。
无论我做什么(我尝试将数字调整为 70 而不是 50,甚至更大),我似乎都无法通过调整 space 来实现 (3)。具体来说,无论我做什么,绘图区域都不会移动。
我做错了什么?
如果在Chart.Plotarea末尾加一个点,就可以看到方法列表。在你的情况下,你正在寻找 .InsideLeft 和 .InsideTop,因为你想调整图表区域的内部距离:
With .Chart.PlotArea
.InsideLeft = 70
.InsideTop = 70
End With