是否使用vba将轴添加到powerpoint中的图表?

是否使用vba将轴添加到powerpoint中的图表?,vba,charts,powerpoint,Vba,Charts,Powerpoint,我在做一个项目。我想检查图表是否有x轴或y轴。如果没有,则添加它。甚至我也想检查x轴或y轴是否有标题。如果没有,请提供标题 我写了一段代码,检查x轴或y轴是否有标题。但如果没有,那么如何添加标题呢 这是一个查找轴标题的代码 Dim oSld As Slide Dim oShp As Shape Dim oShapes As Shapes Dim yaxes as Boolean Dim xaxes as Boolean On Error GoTo Errorhandler: For Each

我在做一个项目。我想检查图表是否有x轴或y轴。如果没有,则添加它。甚至我也想检查x轴或y轴是否有标题。如果没有,请提供标题

我写了一段代码,检查x轴或y轴是否有标题。但如果没有,那么如何添加标题呢

这是一个查找轴标题的代码

Dim oSld As Slide
Dim oShp As Shape
Dim oShapes As Shapes
Dim yaxes as Boolean
Dim xaxes as Boolean

 On Error GoTo Errorhandler:
For Each oSld In ActivePresentation.Slides

 Set oShapes = oSld.Shapes
 For Each oShp In oShapes
     If oShp.HasChart Then

                If oShp.HasChart Then

                    yaxes = oShp.Chart.Axes(xlValue, xlPrimary).HasTitle
                    xaxes = oShp.Chart.Axes(xlCategory).HasTitle

                    'check x axies have title
                    If xaxes <> True Then
                    ' Add title

                    End If 
                    'check y axies have title
                    If yaxes <> True Then
                    ' Add title

                    End If 
                End If
     End If
 Next oShp
Next
将oSld设置为幻灯片
将oShp调暗为形状
模糊不清的人形
作为布尔值的弱雅克斯
作为布尔的Dim-xax
错误转到错误处理程序时:
对于ActivePresentation.Slides中的每个oSld
设置oShapes=oSld.Shapes
对于oShapes中的每个oShp
如果oShp.HASCART那么
如果oShp.HASCART那么
yaxes=oShp.Chart.Axes(xlValue,xlPrimary).hasttle
xaxes=oShp.Chart.Axes(xlCategory).Hasttle
'检查x轴是否有标题
如果xaxes为真,那么
'添加标题
如果结束
'检查y轴是否有标题
如果是真的那么
'添加标题
如果结束
如果结束
如果结束
下一个oShp
下一个
所以在上面的代码中,如果不指定,我还想添加轴


谢谢。

像这样的东西会有用的

  • 保留现有轴和/或标题不变
  • 在不存在轴/标题的位置添加轴/标题

    Dim oSld As Slide
    Dim oShp As Shape
    Dim oShapes As Shapes
    For Each oSld In ActivePresentation.Slides
        Set oShapes = oSld.Shapes
        For Each oShp In oShapes
            If oShp.HasChart Then
                If oShp.HasChart Then
                    With oShp.Chart
                        If Not .HasAxis(xlValue) Then .HasAxis(xlValue) = True
                        If Not .HasAxis(xlCategory) Then .HasAxis(xlCategory) = True
                        If Not .Axes(xlCategory).HasTitle Then .Axes(xlCategory).HasTitle = True
                       If Len(.Axes(xlCategory).AxisTitle.Text) = 0 Then .Axes(xlCategory).AxisTitle.Text = "I'm X"
                        If Not .Axes(xlValue).HasTitle Then .Axes(xlValue).HasTitle = True
                       If Len(.Axes(xlValue).AxisTitle.Text) = 0 Then .Axes(xlValue).AxisTitle.Text = "I'm Y"
                    End With
                End If
            End If
        Next oShp
    Next oSld
    

  • 谢谢brettdj。因为我不知道轴的其他属性,这就是为什么。