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

			

'Force variable declaration Option Explicit 'Variable for controlling if the animation should continue to run Dim Running As Boolean Private Sub CommandButton1_Click() 'Close Command Button 'Dismiss the userform Unload Me End Sub Private Sub UserForm_Activate() 'Set Running to true, while true the animations will continue to run Running = True 'Start the animation sub 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) 'Set running to False to stop the animation Running = False End Sub

How to use:

  1. Copy the above code.
  2. Press Alt + F11, to open the Visual Basic Editor (VBE).
  3. Select workbook in the left-hand frame.
  4. Click Insert - Userform
  5. Click View - Toolbar
  6. Create two Images in the userform
  7. Size each image to the picture file desired, ensure correct file path.
  8. NOTE: For animations to work, *animation* files must be numbered starting with 1 (see attached zip).
  9. From the Toolbar, create a Command Button on the userform.
  10. Right-click the userform and click View Code.
  11. Paste the above code into the blank frame on right.
  12. From the Forms toolbar, create a Command Button.
  13. Assign the macro ShowSplashScreen
 

Test the code:

  1. Save the attached workbook.
  2. Extract all files and folders to the same location (i.e. the Desktop).
  3. Open the Excel file.
  4. Click the Show Splash Screen button.
 

Sample File:

Splash Screen.zip 149.09KB 

Approved by mdmackillop


This entry has been viewed 1127 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express