I'm trying to move a group of pictures in Excel with VBA, this works fine, but I want that the user can see how the picture is moving.
It's for a little game, a "Horse Race".
Here is my code for moving the horses.
Sub TrackProgress()
Dim Tracks() As GroupObject
Dim Agents(), HorseCount As Integer
Dim AgentCount As Integer
Dim TrackCount As Integer
Dim Progress As Double
Dim MaxPx As Double
AgentCount = Sheets("Config").Range("O5").Value
TrackCount = Round(AgentCount / HorsesPerTrack, 0)
ReDim Tracks(1 To TrackCount)
ReDim Agents(1 To AgentCount)
MaxPx = Sheets("Config").Range("O15").Value
Sheets("HorseRaceTrack").Select
For i = 6 To Sheets("Config").Cells(Rows.Count, 5).End(xlUp).Row
If Sheets("Config").Cells(i, 4).Value = "Active" Then
Agents(i - 5) = Sheets("Config").Cells(i, 5).Value
End If
Next i
For i = 1 To AgentCount
If Not IsError(Sheets("Config").Cells(i + 5, 7).Value) Then
Progress = Sheets("Config").Cells(i + 5, 7).Value
Do Until Sheets("HorseRaceTrack").Shapes("Horse_" & Agents(i)).Left >= (MaxPx * Progress)
Sheets("HorseRaceTrack").Shapes("Horse_" & Agents(i)).IncrementLeft 1.3636220472
'Sleep 1000 ' Pferd beweg sich nicht flüssig....
Loop
Else
GoTo NextOne
End If
NextOne:
Next i
End Sub
I already tried to use "sleep 500" but the screen is also freezing
Thanks for your help!
Put a DoEvents
immediately after the .IncrementLeft
. This should allow the worksheet to display the Shape as it moves.
By adjusting the size of the increment, you can get the motion to speed-up or slow-down.