gpt4 book ai didi

vba - Excel VBA : Animation of moving object

转载 作者:行者123 更新时间:2023-12-04 20:55:44 33 4
gpt4 key购买 nike

这是一个有点奇怪的问题。我有一个电子表格,可以在其中移动一些图片,并且正在尝试创建更流畅的“动画”。总运动应该是 20,所以我试图在这个例子中将它拆分(如果我让它工作,我希望添加几帧)。然而,问题是你永远看不到第一个乐章,只看到最后一个乐章。关于如何实现这样的事情的任何想法?

我试过添加 ScreenUpdating 和 AplicationWait 命令,但没有运气。

Public PositionTop As Double
Public PositionLeft As Double
_______________________________________
Sub Animation()
Application.ScreenUpdating = False
Worksheets("Sheet1").Activate

'Frame 1
With ActiveSheet
.Shapes.Range(Array("RandomPicture")).Select
.Shapes("RandomPicture").Top = PositionTop + 10
.Shapes("RandomPicture").Left = PositionLeft
End With

Application.ScreenUpdating = True
Application.ScreenUpdating = False

'Frame 2
With ActiveSheet
.Shapes.Range(Array("RandomPicture")).Select
.Shapes("RandomPicture").Top = PositionTop + 20
.Shapes("RandomPicture").Left = PositionLeft
End With

Application.ScreenUpdating = True

PositionTop = PositionTop + 20

Worksheets("Sheet1").Cells(1, 1).Select

End Sub
______________________________________________
Sub ResetAnimation()
PositionTop = 10
PositionLeft = 20
Worksheets("Sheet1").Activate

With ActiveSheet
.Shapes.Range(Array("RandomPicture")).Select
.Shapes("RandomPicture").Top = PositionTop
.Shapes("RandomPicture").Left = PositionLeft
End With

Worksheets("Sheet1").Cells(1, 1).Select
End Sub

最佳答案

解释上面的评论,你可以尝试这样的事情:

Dim i as long
With ActiveSheet
For i = 10 To 100 Step 10
.Shapes("RandomPicture").Left = i
Application.Wait(Now + TimeValue("0:00:01"))
DoEvents
Next
End With

上面的代码将每秒将您的对象移动 10 步。 HTH。

关于vba - Excel VBA : Animation of moving object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48092043/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com