2014-10-29 118 views
1

嗨,大家好,我正在做一个简单的excel游戏,我只需要笑脸图像作为无尽的亚军类游戏增加。一旦按下播放按钮,我就会向上移动,但我希望它继续移动。有任何想法吗 ?VBA excel增量

这里是我到目前为止的代码:

Sub Play() 

' 
' 

Play Macro 

' 

' 
    ActiveSheet.Shapes.Range(Array("Smiley Face 1028")).Select 
    Selection.ShapeRange.IncrementTop -20.8333070866 

End Sub 

回答

0

你需要把它移到与某种计时器的循环。看到这个例子

Sub Play() 
    Dim shp As Shape 
    Dim r As Double 

    Set shp = ActiveSheet.Shapes("Smiley Face 1028") 
    r = shp.Top 

    Do 
     r = shp.Top 
     If r <= 1 Then Exit Do 
     shp.IncrementTop -1 
     Wait 0.5 '<~~ Wait for 30 seconds 
    Loop 

    MsgBox "Animation Over. :) !!!" 
End Sub 

Private Sub Wait(ByVal nSec As Double) 
    nSec = nSec + Timer 
    While nSec > Timer 
     DoEvents 
    Wend 
End Sub