|
|
|
|
|
|
Excel
|
Animation on a Userform
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
2002
|
Submitted by:
|
Jacob Hilderbrand
|
Description:
|
The attached workbook contains a userform that demonstrates how to control animation images. It also shows how to have multiple animations running at the same time.
|
Discussion:
|
I use this method for my programs to display simple animations on a userform.
|
Code:
|
instructions for use
|
Option Explicit
Dim Running As Boolean
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Activate()
Running = True
Call Animation
End Sub
Private Sub Animation()
Dim x As Integer
Dim y As Integer
Dim MyTimer As Double
DoEvents
x = 1
y = 1
MyTimer = Timer
Do
On Error Resume Next
SplashScreen.Image3.Picture = LoadPicture _
(ThisWorkbook.Path & "\Images\Animation\Flag\" & x & ".Gif")
SplashScreen.Image4.Picture = LoadPicture _
(ThisWorkbook.Path & "\Images\Animation\Pulser\" & y & ".Gif")
On Error GoTo 0
Do
Loop While Timer - MyTimer < 0.07
If x = 8 Then
x = 1
Else
x = x + 1
End If
If y = 11 Then
y = 1
Else
y = y + 1
End If
MyTimer = Timer
DoEvents
Loop While Running
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Running = False
End Sub
|
How to use:
|
- Copy the above code.
- Press Alt + F11, to open the Visual Basic Editor (VBE).
- Select workbook in the left-hand frame.
- Click Insert - Userform
- Click View - Toolbar
- Create two Images in the userform
- Size each image to the picture file desired, ensure correct file path.
- NOTE: For animations to work, *animation* files must be numbered starting with 1 (see attached zip).
- From the Toolbar, create a Command Button on the userform.
- Right-click the userform and click View Code.
- Paste the above code into the blank frame on right.
- From the Forms toolbar, create a Command Button.
- Assign the macro ShowSplashScreen
|
Test the code:
|
- Save the attached workbook.
- Extract all files and folders to the same location (i.e. the Desktop).
- Open the Excel file.
- Click the Show Splash Screen button.
|
Sample File:
|
Splash Screen.zip 149.09KB
|
Approved by mdmackillop
|
This entry has been viewed 1127 times.
|
|