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
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