'How to loop over all objects with a specific name in vba
I am making a game in PowerPoint with vba and I want to loop over all the objects with the name "collider" but it does not work.
Sub getCollision()
Dim curSlide As Slide
Dim curShape As Shape
For Each curSlide In ActivePresentation.Slides
Debug.Print curSlide.SlideNumber
For Each curShape In curSlide.Shapes
If curShape.Name = collider Then
curShape.Left = 10
Debug.Print curShape.Name
Next curShape
Next curSlide
End Sub
Solution 1:[1]
In your code, the If function not ending properly with end if, it will cause debug issue when execution.
If curShape.Name = collider Then
curShape.Left = 10
Debug.Print curShape.Name
end if
- By change the shape.name to correct one with quotation mark, such as curShape.Name = "Hello", then it work properly in my case, you can check the name of the shape in arrange>selection panel in Powerpoint
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

