Excel VBA Home Excel VBA Classic Excel VBA 2010 Excel VBA 365 Examples About

Excel VBA Animation Tutorial


Create Animations with Excel VBA

Learn how to create simple animations in Excel VBA 365 by manipulating object positions. This guide includes practical code examples for horizontal, vertical, and diagonal movements.

Key Concepts

Example 1: Horizontal Animation

Moves an object left-to-right continuously:

Private Sub CmsStart_Click()
repeat:
    With VBAProject.Sheet1.Image1
        .Left = .Left + 1
        DoEvents
        If .Left > 200 Then .Left = 1
    End With
    GoTo repeat
End Sub

Example 2: Vertical Animation

Private Sub StartButton_Click()
repeat:
    With VBAProject.Sheet1.Image1
        .Top = .Top + 1
        DoEvents
        If .Top > 200 Then .Top = 1
    End With
    GoTo repeat
End Sub

Example 3: Diagonal Animation

Private Sub StartButton_Click()
repeat:
    With VBAProject.Sheet1.Image1
        .Top = .Top + 5
        .Left = .Left + 5
        DoEvents
        If .Top > 200 Then .Top = 1
        If .Left > 200 Then .Left = 1
    End With
    GoTo repeat
End Sub
Excel VBA Animation Interface - Start/Reset buttons and moving image
Animation control interface in Excel


Copyright © 2008-2023 Dr. Liew Voon Kiong. All rights reserved.
Last updated:
Privacy Policy | Contact via Facebook