Visio 对象的 VBA 动画

发布于 2024-07-08 08:06:10 字数 368 浏览 6 评论 0原文

我正在尝试使用循环为 Visio 对象设置动画,例如:

For reposition = 2 To 6
    xpos = reposition
    ypos = reposition

    sh1.SetCenter xpos, ypos

    Sleep 1000

Next reposition

虽然这确实将对象从起始位置移动到结束位置,但中间步骤不可见。 延迟后仅显示最终位置。

如果我在循环中放置一个 MsgBox ,那么每个中间位置都是可见的,但必须单击一个分散注意力的中心位置框才能看到这些位置。

如何在没有用户交互和模式窗口覆盖屏幕的情况下使流程可见?

I'm trying to animate Visio objects with a loop, such as:

For reposition = 2 To 6
    xpos = reposition
    ypos = reposition

    sh1.SetCenter xpos, ypos

    Sleep 1000

Next reposition

While this DOES move the object from the starting position to the ending, the intermediate steps are not visible. After a delay only the final position is displayed.

If I put a MsgBox in the loop then each intermediate position is visible but one must click a distracting, center-positioned box in order to see these.

How can I make the flow visible without user interaction and covering of the screen by a modal window?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奢望 2024-07-15 08:06:10

睡觉前尝试使用 DoEvents 语句

Try a DoEvents statement before your sleep

梦萦几度 2024-07-15 08:06:10

谢谢,DJ!
效果非常好。 为了下一个需要示例的人的利益,下面是我的代码,它移动已放置在 Visio 网格上的进程图标并显示连续运动(动画)(查看预览,似乎我的缩进已被消除) ):

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub testa()
    Dim sh1 As Visio.Shape

    Dim pagObj As Visio.Page
    Dim xpos As Double
    Dim ypos As Double

    Set pagObj = ThisDocument.Pages.Item(1)
    Set sh1 = pagObj.Shapes.Item(1)

    Dim reposition As Double

    reposition = 2#

    While reposition < 6#
        xpos = reposition
        ypos = reposition

        sh1.SetCenter xpos, ypos

        DoEvents

        Sleep 100

        reposition = reposition + 0.2
    Wend

End Sub

Thanks, DJ!
That worked perfectly. For the benefit of the next person who needs an example, below is my code which moves a process icon which has been placed on a Visio grid and shows the continuous motion (animation) (looking at the preview it seems that my indentation has been eliminated):

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub testa()
    Dim sh1 As Visio.Shape

    Dim pagObj As Visio.Page
    Dim xpos As Double
    Dim ypos As Double

    Set pagObj = ThisDocument.Pages.Item(1)
    Set sh1 = pagObj.Shapes.Item(1)

    Dim reposition As Double

    reposition = 2#

    While reposition < 6#
        xpos = reposition
        ypos = reposition

        sh1.SetCenter xpos, ypos

        DoEvents

        Sleep 100

        reposition = reposition + 0.2
    Wend

End Sub
淡忘如思 2024-07-15 08:06:10

确保您已将 Application.Screenupdating 设置为 true...我有一个类似的宏,可以对形状进行动画处理,并且我不需要使用 DoEvents 来更新屏幕...

Make sure you have Application.Screenupdating set to true...I have a similar macro that animates a shape and I don't need to use DoEvents to update the screen...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文