maverick
maverick

Reputation: 139

Excel - Adding animation

I am quite new to Excel and so far it has been fun learning it. I have started using Excel for modelling and i have gained enough expertise at it I now wanted to go a step ahead and do a bit of designing on Excel I have a specific requirement. I have 10 sheets in my workbook. I want to add some sort of animation on my first sheet. I currently have a button on my sheet 1. On click of button it unhides all the 9 sheets and allows me to see modelling stuff in them. On clicking one more time it hides all the 9 sheets again.

Now i want to add one more thing to this. On clicking the button i want a light bulb on the sheet to turn on and display a message (along with unhiding the sheets) On clicking one more time i want the light bulb to turn off and hide the sheets again,

Can someone help me with this animation.

Thanks, Sachi

Upvotes: 1

Views: 3919

Answers (2)

Siddharth Rout
Siddharth Rout

Reputation: 149305

Like I said it is very simple. This is how your Button and Bulb looks like.

enter image description here

Shapes used to create the bulb

  1. Straight Connector
  2. Oval
  3. Cloud

Code

Private Sub CommandButton1_Click()
    If CommandButton1.Caption = "Hide" Then

        '
        '~~> Your code here to Hide the Sheets
        '

        ActiveSheet.Shapes("Oval 2").Fill.ForeColor.RGB = RGB(255, 255, 255)

        CommandButton1.Caption = "Unhide"
    ElseIf CommandButton1.Caption = "Unhide" Then

        '
        '~~> Your code here to Unhide the Sheets
        '

        ActiveSheet.Shapes("Oval 2").Fill.ForeColor.RGB = RGB(255, 255, 0)

        CommandButton1.Caption = "Hide"
    End If
End Sub

Upvotes: 3

quantum285
quantum285

Reputation: 1032

To simply make the button change a shapes fill to yellow try this:

ActiveSheet.Shapes("SHAPE NAME").Fill.ForeColor.RGB = RGB(255, 255, 0)

The same idea can be applied to change the fill back. I've been playing with actual animation myself a lot lately too, so if you want to get something a bit more fun than the above than try something like the following. (Create a shape called Oval 1 to demo it with, or change the name to your shapes name)

Sub bulb()
steps = 300
timelimit = 0.005
increments = 255 / steps
counter = 0
r = 0
g = 0
Do
    DoEvents
    counter = counter + 1
    r = r + increments
    g = g + increments
    ActiveSheet.Shapes("Oval 1").Fill.ForeColor.RGB = RGB(r, g, 0)
    timeout (timelimit)
Loop Until counter = steps
End Sub

Sub timeout(duration_ms As Double)
    Start_Time = Timer
    Do
    DoEvents
    Loop Until (Timer - Start_Time) >= duration_ms
End Sub

Will need tweaking to your needs of course but the possibilities playing with this are endless.

Upvotes: 2

Related Questions