Playing Embedded Sound

C

Chris

Hi All,

I'm trying to play an embedded sound file in excel and want to know if there
is a way to do it without it opening another app (e.g. Windows Media Player).
I want to have a sound attached to a form that appears when you open the
workbook.

I am currently using a Wav file in Excel 2007 but can use other file types
if they'll work better.

Thanks
Chris
 
M

Mike K

Chris,

Just a thought. Here is what I have that plays a wav file "without a
player" when a cell condition is met. To use this code as-is, you might try
placing a condition in a cell. Put a 1 in A1, then in A2 use formula
=Alarm(A1,"=1"). Not sure if it will re-evaluate every time, but you can
give it a try.

Mike

From John Walkenbach "Excel 2000 Power Programming"

'Windows API function declaration
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long


Function Alarm(Cell, Condition)
Dim WAVFile As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
On Error GoTo errHandler
If Evaluate(Cell.Value & Condition) Then
WAVFile = ThisWorkbook.Path & "\secalert.wav" 'Edit this statement
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
Alarm = True
Exit Function
End If
errHandler:
Alarm = False
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top