Two Variable Time Function Loop

5SRopp

New Member
Joined
Sep 22, 2010
Messages
29
At every 50 minutes past the hour I want to trigger a randomizer that selects a song to play. For example, at 6:50, 7:50, 8:50, 9:50 etc.. I want a random song to play. Currently my macro executes around 576 times before the first song has played causing the computer to slowdown or crash. Below is my current code. I was thinking I could use something like

For i = 0 To 23
For j =50, Step 60
Application.OnTime TimeValue("i:j:00"), "MyMacro"
Next i
Next j
End For

to loop. Won't this also cause the computer to slow and/or crash?
Please help!



Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub MyMacro()

Application.OnTime TimeValue("00:50:00"), "MyMacro"
Application.OnTime TimeValue("1:50:00"), "MyMacro"
Application.OnTime TimeValue("2:50:00"), "MyMacro"
Application.OnTime TimeValue("3:50:00"), "MyMacro"
Application.OnTime TimeValue("4:50:00"), "MyMacro"
Application.OnTime TimeValue("5:50:00"), "MyMacro"
Application.OnTime TimeValue("6:50:00"), "MyMacro"
Application.OnTime TimeValue("7:50:00"), "MyMacro"
Application.OnTime TimeValue("8:50:00"), "MyMacro"
Application.OnTime TimeValue("9:50:00"), "MyMacro"
Application.OnTime TimeValue("10:50:00"), "MyMacro"
Application.OnTime TimeValue("11:50:00"), "MyMacro"
Application.OnTime TimeValue("12:50:00"), "MyMacro"
Application.OnTime TimeValue("13:50:00"), "MyMacro"
Application.OnTime TimeValue("14:50:00"), "MyMacro"
Application.OnTime TimeValue("15:50:00"), "MyMacro"
Application.OnTime TimeValue("16:50:00"), "MyMacro"
Application.OnTime TimeValue("17:50:00"), "MyMacro"
Application.OnTime TimeValue("18:50:00"), "MyMacro"
Application.OnTime TimeValue("19:50:00"), "MyMacro"
Application.OnTime TimeValue("20:50:00"), "MyMacro"
Application.OnTime TimeValue("21:50:00"), "MyMacro"
Application.OnTime TimeValue("22:50:00"), "MyMacro"
Application.OnTime TimeValue("23:50:00"), "MyMacro"



Dim MyNumber As Integer
Dim Song As String
Randomize Timer
MyNumber = Application.WorksheetFunction.RoundUp(Rnd() * 16, 0)

Select Case True
Case MyNumber = 1
Song = "C:\Users\iowa\Music\06 If It's Love1.mp3"


Case MyNumber = 2
Song = "C:\Users\iowa\Music\06 If It's Love 1.mp3"

Case MyNumber = 3
Song = "C:\Users\iowa\Music\Magic (feat. Rivers Cuomo of Weezer).mp3"

Case MyNumber = 4
Song = "C:\Users\iowa\Music\Rich Girl.mp3"

Case MyNumber = 5
Song = "C:\Users\iowa\Music\Katy Perry - Teenage Dream - Single (HQ).mp3"

Case MyNumber = 6
Song = "C:\Users\iowa\Music\OAR - This Town.mp3"

Case MyNumber = 7
Song = "C:\Users\iowa\Music\Spin Doctors - Two Princes.mp3"

Case MyNumber = 8
Song = "C:\Users\iowa\Music\Zack Brown Band - Chicken Fried.mp3"



End Select

Dim handle As Long
handle = ShellExecute(0, "Open", Song, 0, 0, SW_SHOWNORMAL)


End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,224,521
Messages
6,179,282
Members
452,902
Latest member
Knuddeluff

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