Question

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?

Was it helpful?

Solution

Try a DoEvents statement before your sleep

OTHER TIPS

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

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top