Macro to play music

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
Is there anyway in the world for me to tell excel to play music every morning at 6:00. If so, I will truly believe Excel can do anything.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
you may truly believe it

Hello, try this code
Code:
'http://support.microsoft.com/?kbid=213777
'This function declaration must be entered onto a single line.
Private Declare Function PlayIt Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Sub PlaySound()
    If Application.CanPlaySounds Then
        'Substitute the path and filename of the sound you want to play
        Call PlayIt("c:\windows\media\chimes.wav", 0)
    End If
End Sub
to play it at 6 o'clock see OnTime in the helpfiles
to do it in a loop: http://www.mrexcel.com/board2/viewtopic.php?t=196054
although I doubt that you can shut of the computer (never tested it: let me know :) )

kind regards,
Erik
 
Upvote 0
This will play MP3's on your PC, using the Windows Media Player automatically. Just change the file name of the MP3 you want to play and change the Folder that file is in, in the code below. Add this part of the code to a Standard code module, like: Module1!

You just need to add the OnTime timer code at the bottom, must be placed in the "ThisWorkbook" code module!

Note: The Workbook must be open for this to work. I do not know if some "Screen Savers" will stop the OnTime Event?



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


Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long


Sub myMP3Play()
'Standard Module Code, like: Module1!

Dim thisFolder$, MediaPlayer$, theFile$

theFile = "Q3.mp3"
thisFolder = "C:\Program Files\Windows Media Player\"


'Hide MediaPlayer and play!
'Call ShellExecute(FindWindow("xlMain", vbNullString), _
' "Open", theFile, vbNullString, thisFolder, 0)


'Minimize MediaPlayer and play!
'Call ShellExecute(FindWindow("xlMain", vbNullString), _
' "Open", theFile, vbNullString, thisFolder, 2)



'Show MediaPlayer and play!
Call ShellExecute(FindWindow("xlMain", vbNullString), _
"Open", theFile, vbNullString, thisFolder, 1)

End Sub



Private Sub Workbook_Open()
'ThisWorkbook code, Only!
'At 6:00 AM each day run my code!


Application.OnTime TimeValue("06:00:00"), "myMP3Play"
End Sub
 
Upvote 0
I'm not going to shut it down....I'm going to leave the workbook open tonight and see if it works
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

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