0
votes

I'm new to VBA and I'm trying to do something that looks simple to me, but very hard to realise.

Context:

I have a PPT presentation with 20 slides, in which each slide has 21 shapes, but the last one. Everytime I Want to add a new shape, it goes on the 1st slide, and thus I have to move every shapes to make room for the new one.

My problem: I found out how to move a shape to where I want using this code

With ActiveWindow.Selection.ShapeRange
  .Left = XXX 'change the number for desired x position
  .Top = XXX 'change the number for desired y position
End With

However this works only if I select the said 1st shape. Because I have hundreds of shapes, naming them all to move them would be too time consuming. So what I'd like to do is to tell VBA to Select the shape that is there:

.Left = 50
.Top = 50

And move it there

.Left = 140
.Top = 50

This looks very simple, but somehow I can't figure out how to do it. This thread comes close to what I want but not quite yet.

Thank you in advance.

1
I think I figured it out. Wow that was fast. [code] If .Type = msoAutoShape _ And .Left = 50 _ And .Top = 50 Then .Left = 140 .Top = 50 [/code] - user6002622

1 Answers

0
votes

You could add the shape to a given slide and thereby alleviate the need to move it:

' Adds a shape to a given slide or if no slide passed, to the current slide in view
' Assumes code is running in PowerPoint VBE
Sub AddShapeToSlide(Optional oSld As Slide)
  If oSld Is Nothing Then Set oSld = ActiveWindow.View.Slide
  With oSld.Shapes.AddShape(msoShapeRectangle, 140, 50, 200, 200)
    .Name = "My New Shape"
    ' Apply other formatting here
  End With
End Sub