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.
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
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
 

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
I'm not going to shut it down....I'm going to leave the workbook open tonight and see if it works
 

Watch MrExcel Video

Forum statistics

Threads
1,114,381
Messages
5,547,608
Members
410,802
Latest member
DataMgmtAnalyst7
Top