Sound

Orangeanorak

Active Member
Joined
Nov 22, 2002
Messages
276
Office Version
  1. 365
Platform
  1. Windows
Cqn you please tell me how to make a sound play if a certain phrase appears in a cell i.e if John 2 appears in cell L5 play sound. The microsoft sounds will do. Thanks John o_O
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
For wav files - In the sheet code


Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("l5")) Is Nothing Then
Exit Sub
Else

If Cells(5, 12) = "John2" Then

Call PlaySound("D:\D Drive\GEORGE\Music\music\duel_a.wav", 0)

End If
End If
End Sub


and in a module

Declare Function PlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal wavFile As String, _
ByVal lNum As Long) As Long
 
Upvote 0
Hi George,
Was just checking this out and wondering if you know how to have these same conditions ("John2" in L5 for instance) make it play some actual music (like an MP3 from the hard drive), instead of just one of the standard windows noises. I'm thinking the change would be in the code in the standard module (somewhere in the area of "winmm.dll" Alias _ "sndPlaySoundA") and the path in my sheet module code would be more like: "C:\Program Files\Music Folder\Song Name.MP3. Do you know of a way to do this also?

Thanks,
HalfAce
 
Upvote 0
The wav file was an actual song from my hard drive, but the following works just as well

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If ActiveCell.Text = "" Then
Exit Sub
Else
Cmd = "Start " & Chr(34) & ActiveCell.Text & Chr(34)
Shell Cmd
On Error Resume Next
End If
End Sub

If you put the full name and path in the cell it will play
eg C3 is C:\Program Files\Music Folder\Song Name.mp3

You will have to be a bit patient in waiting for your player to load up however.
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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