Fun code

GeorgeB

Board Regular
Joined
Feb 16, 2002
Messages
239
Here's some code that will pop up multiple stars on a worksheet at one second intervals and then remove them.

Public Sub ShowStars()
Randomize
StarWidth = 50
StarHeight = 50
For i = 1 To 100
TopPos = Rnd() * (ActiveWindow.UsableHeight - StarHeight)
LeftPos = Rnd() * (ActiveWindow.UsableWidth - StarWidth)
Set NewStar = ActiveSheet.Shapes.AddShape _
(msoShape4pointStar, LeftPos, TopPos, StarWidth, StarHeight)
NewStar.Fill.ForeColor.SchemeColor = Int(Rnd() * 56)
Delay 0.01
DoEvents
Next i

Application.Wait Now + TimeValue("00:00:01")

Set myShapes = Worksheets(1).Shapes
For Each shp In myShapes
If Left(shp.Name, 9) = "AutoShape" Then
shp.Delete
Delay 0.01
End If
Next

End Sub


Public Sub Delay(rTime As Single)
'delay rTime seconds (min=.01, max=300)
Dim oldTime As Variant
'safety net
If rTime< 0.01 Or rTime > 300 Then rTime = 1
oldTime = Timer
Do
DoEvents
Loop Until Timer - oldTime > rTime

End Sub



_________________
George
This message was edited by GeorgeB on 2002-04-02 21:24
 
Hi jbyrne
Easy way, from the forms toolbar put a button on the sheet and attach it to the procedure (ShowStars). Just right click on the button, select "Assign macro"
Enjoy
George
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Thanks George,

I seem to be getting a Compile error. Variable not defined mssg. When I click ok, The public sub showstars is highlighted in yellow.

Jim
 
Upvote 0
Jim
How did you enter the code?
There are two separate procedures and they need to go into a standard module.
 
Upvote 0
George,

I copied your code then clicked on the VB editor and pasted. I guess I did it wrong.
 
Upvote 0
Jim
Sorry I gave you a bum steer. The code has to go in the sheet not a standard module.
Use the insert procedure and then copy and paste the code in. Two separate procedures.
 
Upvote 0
George,

When you say the code has to go into the sheet. I don't know much about coding or VBA, so excuse my ignorance.....I'm learning as I go.
 
Upvote 0
OK here goes
Open a fresh workbook, right click on the sheet tab, select “View code”
This will put you into the VBE (Visual Basic Editor) At the top of the
Screen click on “Insert” select “Procedure” name them the same as my post
and paste in the code. Do this twice, once for each procedure.
Good luck
 
Upvote 0
Aloha,

If anyone has the time and patience, can you walk me through this.

:oops:

I get stuck at the Insert/Procedure the window won't accept any names.

Brian
This message was edited by Brian from Maui on 2002-04-06 22:55
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top