2012-01-31 58 views
2

我正在一个项目上工作。在那我想检查图表是否有x或y轴。如果没有,然后添加它。即使我也想检查x或y轴是否有标题。如果没有,则提供标题。使用vba添加坐标轴到powerpoint图表?

因为我写了一个代码,检查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 

所以一个代码。

谢谢。

回答

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 
    
+0

感谢brettdj轴/标题。因为我不知道轴的其他属性多数民众赞成在为什么。 – 2012-02-01 03:35:22