打开/关闭 PowerPoint VBA 轴

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

我如何将这两个组合起来使宏成为一个切换,而不是需要两个不同的宏来打开和关闭轴?

我似乎无法让它与 If else 语句一起使用。

Sub Format_linechart_AxisTrue()

    Dim sld As slide
    Dim shp As shape
    Dim chart As chart
    Dim sr As series
    Dim i As Long
    
    Set sld = Application.ActiveWindow.View.slide
    
    For Each shp In sld.Shapes
        If shp.HasChart Then
            Set chart = shp.chart
            For i = 1 To chart.SeriesCollection.Count
                If chart.HasAxis(xlValue) = False Then chart.HasAxis(xlValue) = True
            Next i
        End If
    Next shp

End Sub

Sub Format_linechart_AxisFalse()

    Dim sld As slide
    Dim shp As shape
    Dim chart As chart
    Dim sr As series
    Dim i As Long
    
    Set sld = Application.ActiveWindow.View.slide
    
    For Each shp In sld.Shapes
        If shp.HasChart Then
            Set chart = shp.chart
            For i = 1 To chart.SeriesCollection.Count
                If chart.HasAxis(xlValue) = True Then chart.HasAxis(xlValue) = False
            Next i
        End If
    Next shp

End Sub
vba powerpoint
1个回答
0
投票

如果您需要单个宏能够处理这两种情况连续运行您应该替换这部分:

    For i = 1 To chart.SeriesCollection.Count
         If chart.HasAxis(xlValue) = True Then chart.HasAxis(xlValue) = False
    Next i

使用此改编代码:

    For i = 1 To chart.SeriesCollection.Count
         If chart.HasAxis(xlValue) = True Then 
            chart.HasAxis(xlValue) = False
         Else
            chart.HasAxis(xlValue) = True
         End if
    Next i

现在,在第二次运行时,它会做相反的事情......

© www.soinside.com 2019 - 2024. All rights reserved.