Question

I am working on one project. In that i want to check if chart have x or y axes or not. If not then add it. even i also want to check if x or y axes have title or not. if not then provide the title.

as i wrote one code which is checking that if x or y axes have title or not. but if not then how to add title to it?

This is a code for finding axes title

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

So in above code i also wants to add axes if not assign.

Thanks.

Was it helpful?

Solution

Something like this will

  1. leave existing axes and/or titles intact
  2. add axes/titles where they don't exist

    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
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top