Results 1 to 12 of 12
  1. #1
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Animate a rolling ball (Excel ALL)

    Hi all,

    I have a small red circle (ball) on a spreadsheet. I would like the ball to roll towards the screen and in doing so get larger as it comes 'closer'. The only amination sequences I could find using google are for graphic programs. Is it possible to guide me into the right direction to animate this ball on the worksheet.

    I started code that looks like this, but I know it is WAY off track. All I know is that there is obviously loops involved.
    <pre>Sub Animate()
    Dim myBall As Shape
    Dim w As Integer
    Dim h As Integer
    Set myBall = Worksheets(1).Shapes(1)
    For w = 20 To 100
    For h = 20 To 100
    myBall.Width = w
    myBall.Height = h
    Next h
    Next w
    End Sub
    </pre>

    Any help would be appreciated, but it is not important as it is a personal learning curve...not business related. TX
    Regards,
    Rudi

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Animate a rolling ball (Excel ALL)

    > I would like the ball to roll towards the screen

    Do you only want the circle to increase in size, or should it move also? And if so, how? "Towards the screen" is not a valid option, since it is already on the screen.

  3. #3
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Animate a rolling ball (Excel ALL)

    Since you ask about movement, that would be great. I simply suggested about growing towards the screen to keep it simple. However, let me really go out on the limb and ask if it could, "roll down the H column getting larger as it gets to the bottom of the screen".

    Just a small example will suffice. I just need to know how to string the animation together. Any greater or elaborate movement I can do after.

    Cheers
    Regards,
    Rudi

  4. #4
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Animate a rolling ball (Excel ALL)

    Howdy do da

    The problem with adjusting the circle with H and W is you first create an ellipse and then it broadens to form a circle. What you need to do is get the height and width to grow at the same time (ish) .

    Also you need to halt the animation otherwise it immediately grows to the larger size. Use Application.Wait and remove a loop like so

    <pre>Sub Animate()
    Dim myBall As Shape
    Dim w As Integer
    Set myBall = Worksheets(1).Shapes(1)
    For w = 20 To 100

    myBall.Width = w
    myBall.Height = w
    Application.Wait (Now() + TimeValue("00:00:01"))
    Next w

    End Sub
    </pre>

    Jerry

  5. #5
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Animate a rolling ball (Excel ALL)

    Thx Jezza...much better than my code. Mine went from rugby to soccer to rugby to soccer VERY QUICKLY! <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15>
    Cheers

    Another Q:
    What is the difference between Application.Wait and Application.OnTime? I have always used OnTime to slow procedures. I never knew about Wait. TX for the tip!!
    Regards,
    Rudi

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Animate a rolling ball (Excel ALL)

    Similar to Jerry's, with a bit of movement added:

    Sub Animate()
    Dim i As Integer
    With Worksheets(1).Shapes(1)
    .Top = 10
    .Left = 10
    .Width = 5
    .Height = 5
    For i = 1 To 50
    .Top = .Top + 10
    .Left = .Left + 10
    .Width = .Width * 1.1
    .Height = .Height * 1.1
    Application.Wait Now + TimeSerial(0, 0, 1)
    Next i
    End With
    End Sub

  7. #7
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Animate a rolling ball (Excel ALL)

    Application.Wait stops the macro execution and does not allow anything else to happen until the wait time has expired. Application.OnTime schedules a macro to execute at a time in the future and then immediately returns to the macro that called it.
    Legare Coleman

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Animate a rolling ball (Excel ALL)

    Application.Wait simply, er, waits, and then continues execution where it paused.
    Application.OnTime calls the same or another macro after the specified time.

  9. #9
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Animate a rolling ball (Excel ALL)

    Awesome... I can work with this code.

    Tx, guys. You did it again!

    HANS - How BIG is your screen????? That ball just kept comin' - <img src=/S/yikes.gif border=0 alt=yikes width=15 height=15> <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15>

    Tx Legare. I was confusing myself (again <img src=/S/grin.gif border=0 alt=grin width=15 height=15>) with the Timer function. Seen in <post#=50747>post 50747</post#> (tx to Leif reading that post!!)

    PS: How do I roll it at .5 seconds? TX
    Regards,
    Rudi

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Animate a rolling ball (Excel ALL)

    Application.OnTime and Application.Wait don't work with fractions of a second.

    If you want smooth and fast animation, I'd suggest using another application than Excel.

  11. #11
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    Surrey, United Kingdom
    Posts
    1,001
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Animate a rolling ball (Excel ALL)

    Hi Rudi

    Anything here that might help

    http://books.google.com/books?id=L6mWbkFhk...HMNfI#PPA196,M1

    Cheers

    Steve
    Cheers

    Steve

    Asking the questions everbody wants the answers too but feels too stupid to ask themselves :-)

  12. #12
    Gold Lounger
    Join Date
    Feb 2004
    Location
    Cape Town, RSA
    Posts
    3,444
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Animate a rolling ball (Excel ALL)

    Tx Steve. The link is taking a while to load...traffic on my server seems heavy. I'll have a look at the link when its quieter. Seems to want to load some animated clips of a VBA book.
    Cheers
    Regards,
    Rudi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •