Hi,
I'm placing a grid of shapes on a slide using vba. The first created shape (called shpOrig) is my template, which is then duplicated several times. There are more rows in my original code, but I've reduced all non necessary lines.
I'm not that familiar with coding in powerpoint, more comfortable with excel, so I actually tried this in Excel first and it went well. Using the same code in powerpoint, just making sure Slide is used instead of Worksheet, it didn't go that well - I got runtime 13, Type Mismatch.
Sub CreateShapes()
Dim TargetSlide As Slide
Dim shpOrig As Shape
Dim shpCopy As Shape
Dim x As Long
Dim y As Long
Set TargetSlide = ActivePresentation.Slides(1)
Set shpOrig = TargetSlide.Shapes.AddShape(msoShapeOval, 0, 0, 40, 40)
For y = 0 To 9
For x = 0 To 9
Set shpCopy = shpOrig.Duplicate
shpCopy.Left = 100 + 40 * x
shpCopy.Top = 10 + 40 * y
Set shpCopy = Nothing
Next x
Next y
End Sub
The line that throws an error is
Set shpCopy = shpOrig.Duplicate
A few odd things.
The shpOrig is placed on the slide as well as the first copied shape, even though it's not placed correctly since Left and Top properties have not yet kicked in. So I get a copy even though when hovering over shpCopy it says "shpCopy = Nothing"
The error says Type Mismatch, but both shapes are declared as Shape. If I change the shpCopy from Shape to Variant it works. But I'm not in the mood to just accept a working solution - I'm puzzled why it can't be declared as Shape, and why two equally declared objects get a mismatch. As I said before, this works in excel.
Have I missed something that can't be done in powerpoint?