Добавить оси в диаграмму в PowerPoint с помощью VBA? - PullRequest
2 голосов
/ 31 января 2012

Я работаю над одним проектом. В этом я хочу проверить, есть ли у диаграммы оси 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

Так что в приведенном выше коде я также хочу добавить оси, если не назначен.

Спасибо.

1 Ответ

1 голос
/ 31 января 2012

Примерно так

  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
    
...