I have a lot of squares that will hide a picture behind them.
I will repeat this process in many slides in a ppt, That's why I want it to be random.
I am new to macros and don't understand them that well.
Is there a way to make a random square disappear and then after 2 seconds, another random square disappears, and so on? Until I stop it or all squares have disappeared.
Thank you in advance.
I have this code that makes the square disappear when clicked that I got from google.
Sub triggerMe()
Dim osld As Slide
Dim oshp As Shape
Dim oeff As Effect
On Error Resume Next
Set oshp = ActiveWindow.Selection.ShapeRange(1)
If Not oshp Is Nothing Then
Set osld = oshp.Parent
Set oeff = osld.TimeLine.InteractiveSequences.Add.AddEffect(oshp, msoAnimEffectFade, , msoAnimTriggerOnShapeClick)
With oeff
.Timing.TriggerShape = oshp
.Exit = True
End With
End If
End Sub
This is a screenshot of the slide:
Here is the ppt link
So this block of code works. It was a lot more complicated than I thought.
Sub Dala()
currentslide = ActiveWindow.Selection.SlideRange.SlideIndex
Dim slideShapes As shapes
Dim slideShape As Shape
Dim osld As Slide
Dim oshp As Shape
Dim oeff As Effect
'Get shapes for the slide
Set slideShapes = ActivePresentation.Slides(currentslide).shapes
Dim MyListOfNumbers(0 To 500) As Integer
MyListOfNumbers(0) = 0
Dim r As Variant
Dim x As Integer
Dim exist As Boolean
Dim i As Integer
For Each slideShape In slideShapes
x = Random(slideShapes.Count)
'So that it does not double animate the same square again
For Each r In MyListOfNumbers
If r = x Then
exist = True
End If
Next r
'Animates and add it to the array
If exist = False Then
MyListOfNumbers(i) = x
Set oshp = slideShapes(x)
Set osld = oshp.Parent
On Error Resume Next
Set oshp = oshp
If Not oshp Is Nothing Then
Set osld = oshp.Parent
Set oeff = osld.TimeLine.MainSequence.AddEffect(oshp, msoAnimEffectFade, , msoAnimTriggerAfterPrevious)
With oeff
.Timing.TriggerDelayTime = 1
.Exit = True
End With
End If
i = i + 1
End If
exist = False
Next slideShape
End Sub
Function Random(High As Integer) As Integer
'Generates a random number less than or equal to
'the value passed in High
Randomize
Random = Int((High * Rnd) + 1)
End Function