There are many ways to animate within excel.
1) Probably the easiest is to use a Do Loop in conjunction with the Key word DoEvents.
2) Using an ActiveX control of some sought eg.
- - using API's eg comctrl32.dll (See here!) - This uses AVI Files
Except for the ActiveX controls, the basics are the same, that is you are moving a Picture in and out of view either by making one picture visible and all others invisible or just bringing one to the forefront of another to give you the impresion of movemet.
Animation:
There are many ways to animate within excel.
Here are some examples.
1st we will start off with simple string animation within a cell to give you the idea of the basics of looping.
Sub Animate_String()
Dim sTxt As String
Dim x As Integer, y As Integer
Dim Start, delay
sTxt = "Hi there!!"
For y = 1 To 15 '15 Loops through the scrolling
For x = 1 To 30 'Index number of times
Start = Timer 'Set start to internal timer
delay = Start + 0.15 'Set delay for .15 secs
Do While Timer < delay 'Do the display routine
[D6] = Space(x) & sTxt 'Show 1 str @ a time
DoEvents 'do there things
Loop 'Loop until delay is up
DoEvents
Start = Timer 'and reset the timer
delay = Start + 0.15 'and the delay
Next x 'Show the next str
Next y 'Do this again - 15
[D6] = "" 'Reset
End Sub
Now we will complicate it a bit and make 2 Text strings move from alternate sides.
This routine was to help Jack in the UK.
Option Explicit
Sub JacksRoutine()
Dim sTxt As String
Dim yTxt As String
Dim x As Integer, y As Integer
Dim Start, Delay
Dim myCell, myCell2
Dim Indexer As Single
Dim blnRight As Boolean
On Error Resume Next
Set myCell = Range("B2")
Set myCell2 = Range("D3")
Indexer = 100
Application.DisplayStatusBar = True
Application.StatusBar = "... Select Cell to Stop and Edit " & _
"or Wait for Flashing to Stop! "
sTxt = "JackintheUK's Work : " & Format$(Now, "d mmmm yyyy") & "!!!!!!!!"
yTxt = "To Help Jack!"
Do While Range("A1").Value <> ""
DoEvents
For y = 1 To 2 'Indexer Loops through the scrolling
For x = 1 To Indexer 'Index number of times
Start = Timer 'Set start to internal timer
Delay = Start + 0.02 'Set delay for .15 secs
Do While Timer < Delay 'Do the display routine
If blnRight Then 'have u reached the right hand side
[B2] = Space(Indexer - x) & sTxt
[D3] = Space(x) & yTxt 'Show 1 str @ a time
Else
[B2] = Space(x) & sTxt
[D3] = Space(Indexer - x) & yTxt 'Show 1 str @ a time
End If
DoEvents
Loop 'Loop until delay is up
Start = Timer 'and reset the timer
Delay = Start + 0.02 'and the delay
If x = Indexer Then blnRight = Not (blnRight) 'True or false
Next x 'Show the next str
Next y
Loop 'Do this again
[B2] = "" 'Reset
[D3] = ""
JACK:
Application.StatusBar = False
Application.DisplayStatusBar = Application.DisplayStatusBar
End Sub
This technique can be used for image/pictures. All you need is a sequence of Pictures.
The easiest way to get a sequene of pictures is to download an animated gif file and load it into a graphics program such as Paintshop Pro available here Paintshop Pro
Here are some example pages that contain Animated Gif files that you can use.
Shows you how it may look in Excel, to use the images Just right click and Saveas.
Then load it in your Animation graphics program.
WebBrowser control:
Here is a workbook that shows you how to use the WebBrowser control to animate animated gif files.
Macromedia Flash
Here are some samples of Macromedia Flash files that you can use in a Userform.
Please note:
More to come on programing these for userforms:
Files to be made available soon.....please be patient.
Thanks for visiting my site lucky visitor:
This page was last updated on: March 22, 2009
Copyright © 2002. XcelFiles. All Rights Reserved Ivan F Moala
Putting it together:
Using some of the techniques above, I managed to do this some time ago, in fact it was one of the very 1st ones I did when I first started programing....so the programing is crude @ best :-)
Here is an example of some animation - simulating a trojan virus.
WARNING: Some Virus checkers may warn you of the existance of a Virus, I assure you that this is NOT the case and that the file has been checked. Never the less IF IN DOUBT THROW IT OUT !!
Here is a routine that highlights the fonts by TSTOM
If you do use the Webbrowser control, one of it's weaknesses is that you need to reference the gif either to your local drive OR a networked drive (Internet).
If you have found this file useful then consider donating. Why Donate ?