Wookiee213
New Member
- Joined
- Oct 16, 2014
- Messages
- 34
Hi All
I’m very new to VBA and have run into a problem while adding some simple “animation” (moving images around the screen) to a system I’m developing.
I have a sub which moves a specified image around the screen, I have tested this and it seems to work fine. However when I call it multiple times it seems to stop updating the display/screen with the full animations. But when I insert a msgbox between the Calls then it all works as expected, which leads to me think the issue is probably down to Excel not handling such loops well when changing the display or perhaps there’s a memory issue.
Either way I’d appreciate any advice you can offer on this issue.
Example below (I have a sub which establishes the import of the pictures, their size and start position which is not covered here)
Call One("image one", 400, "UP",)
'MsgBox "pause" ‘with these uncommented it works fine
Call Two("image two", 10, "NONE") ‘this will be displayed at the point the first image reached
'MsgBox "pause" ‘with these uncommented it works fine
Call Three("image three", 400, "DOWNRIGHT") ‘this will start at the point image 2
I’m very new to VBA and have run into a problem while adding some simple “animation” (moving images around the screen) to a system I’m developing.
I have a sub which moves a specified image around the screen, I have tested this and it seems to work fine. However when I call it multiple times it seems to stop updating the display/screen with the full animations. But when I insert a msgbox between the Calls then it all works as expected, which leads to me think the issue is probably down to Excel not handling such loops well when changing the display or perhaps there’s a memory issue.
Either way I’d appreciate any advice you can offer on this issue.
Example below (I have a sub which establishes the import of the pictures, their size and start position which is not covered here)
Call One("image one", 400, "UP",)
'MsgBox "pause" ‘with these uncommented it works fine
Call Two("image two", 10, "NONE") ‘this will be displayed at the point the first image reached
'MsgBox "pause" ‘with these uncommented it works fine
Call Three("image three", 400, "DOWNRIGHT") ‘this will start at the point image 2
Code:
Sub movePic(thePic As String, moveIt As Double, picDir As String)
Application.ScreenUpdating = True
Dim animLoop As Double
Let animLoop = 1
For animLoop = 1 To moveIt
With Workbooks(thisFile).Worksheets("Control").Pictures(thePic)
Select Case picDir
Case Is = "LEFT"
.Left = .Left - 1
Case Is = "RIGHT"
.Left = .Left + 1
Case Is = "UP"
.Top = .Top - 1
Case Is = "DOWN"
.Top = .Top + 1
Case Is = "DOWNLEFT"
.Top = .Top + 1
.Left = .Left - 1
Case Is = "DOWNRIGHT"
.Top = .Top + 1
.Left = .Left + 1
Case Is = "UPLEFT"
.Top = .Top - 1
.Left = .Left - 1
Case Is = "UPRIGHT"
.Top = .Top - 1
.Left = .Left + 1
Case Is = "NONE"
.Top = .Top
.Left = .Left
End Select
'.Top = .Top - 1
'.Left = .Left + 1
Application.ScreenUpdating = True
End With
Next animLoop
Workbooks(thisFile).Worksheets("Control").Pictures(thePic).Delete 'removes it after demo
End Sub