【问题标题】:Add axes to chart in powerpoint using vba?使用vba将轴添加到PowerPoint中的图表?
【发布时间】:2012-02-01 00:55:30
【问题描述】:

我正在做一个项目。在那我想检查图表是否有 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

所以在上面的代码中,如果没有分配,我也想添加轴。

谢谢。

【问题讨论】:

    标签: vba charts powerpoint


    【解决方案1】:

    这样的事情会

    1. 保持现有坐标轴和/或标题不变
    2. 在不存在的地方添加坐标轴/标题

      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。因为我不知道轴的其他属性,这就是为什么。
    猜你喜欢
    • 1970-01-01
    • 2011-11-21
    • 2010-10-07
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多