我必须循环查看给定演示文稿中的每个图表并调整其Y轴。
我从网上拷贝了代码并进行了调整。
1.该代码是为Excel编制的。
我做了哪些更改才能在PowerPoint中运行?
1.在Excel中,我在活动工作表中有17个标题相似的图表。
一些图表被调整,而另一些保持原样。
Sub Chartaxes()
Dim cht As ChartObject
Dim srs As Series
Dim FirstTime As Boolean
Dim MaxNumber As Double
Dim MinNumber As Double
Dim MaxChartNumber As Double
Dim MinChartNumber As Double
Dim Padding As Double
'Input Padding on Top of Min/Max Numbers (Percentage)
Padding = 0.1 'Number between 0-1
'Optimize Code
Application.ScreenUpdating = False
'Loop Through Each Chart On ActiveSheet
For Each cht In ActiveSheet.ChartObjects
'First Time Looking at This Chart?
FirstTime = True
'Determine Chart's Overall Max/Min From Connected Data Source
For Each srs In cht.Chart.SeriesCollection
'Determine Maximum value in Series
MaxNumber = Application.WorksheetFunction.Max(srs.Values)
'Store value if currently the overall Maximum Value
If FirstTime = True Then
MaxChartNumber = MaxNumber
ElseIf MaxNumber > MaxChartNumber Then
MaxChartNumber = MaxNumber
End If
'Determine Minimum value in Series (exclude zeroes)
MinNumber = Application.WorksheetFunction.Min(srs.Values)
'First Time Looking at This Chart?
FirstTime = False
Next srs
'Rescale Y-Axis
cht.Chart.Axes(xlValue).MinimumScale = 0
cht.Chart.Axes(xlValue).MaximumScale = MaxChartNumber * (1 + Padding)
Next cht
'Optimize Code
Application.ScreenUpdating = True
End Sub
参考图片:
其中一张幻灯片
链接数据(excel文件)
1条答案
按热度按时间piok6c0g1#
请尝试下一个适应版本,能够在
Outlook
中工作。VBA Outlook没有Min
,Max
函数,我也构建了它们:请测试它并发送一些反馈。
编辑日期:
请测试更新后的版本。它将对前三个图表使用相同的最大比例,计算第四个图表的最大比例,并对其余图表使用该比例: