A family of Microsoft presentation graphics products that offer tools for creating presentations and adding graphic effects like multimedia objects and special effects with text.
Thanks for the code.
Every box on a slide is a shape. This means that if you have a title on a slide with 2 charts, you have 3 shapes on the slide. So it's a good idea to test whether the shape has a chart is before applying the chart resizing:
With ActiveWindow.Selection.ShapeRange
If .HasChart Then
Perform Action
End If
End With
You specced your variables as Doubles, but if you check the help for Width and the other parameters, PowerPoint uses a Single. If you specify the number type when declaring, it has to be the same type that the parameter actually uses.
You're depending on the Selection object. This can be a good thing for the first selected chart that is used as the position model for the others. But to apply that position automatically to all the other charts, the selection object won't work. Instead you need to loop through each slide in the presentation. On each slide, you loop through all shapes, checking for whether a shape has a chart. Then you only apply the positioning to shapes that meet the criteria:
Sub ResizeCharts()
Dim w As Single
Dim h As Single
Dim l As Single
Dim t As Single
With ActiveWindow.Selection.ShapeRange(1)
If .HasChart = True Then
w = .Width
h = .Height
l = .Left
t = .Top
Else
MsgBox "Please select a chart with the correct position and size"
End If
End With
Dim objSlide As Slide, objShape As Shape
For Each objSlide In ActivePresentation.Slides
For Each objShape In objSlide.Shapes
If objShape.HasChart Then
With objShape
.Width = w
.Height = h
.Left = l
.Top = t
End With
End If
Next objShape
Next objSlide
End Sub
Please note that if there are ever 2 charts per slide, they will end up on top of one another using this code.