How do you play a wav file when a cell value changes?

dwebb03

New Member
Joined
Aug 6, 2003
Messages
22
How can i trigger this code when Cell A1 changes to a value greater 77, or is there another way this is all I could find while searching. Thanx in advance


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

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Sub PlayWAV()
WAVFile = "hal.wav"
WAVFile = ThisWorkbook.Path & "\" & WAVFile
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub
 
Re: Thanx still trying

always restrict problems to the essential
a good car doens't work without fuel
these events should run
when you change a value
yes eventually but I was just trying to learn how to get it to work with just changing the value in the cell manually. I changed it to calculate but that doesn't seem to work.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
        MsgBox "change"
End Sub
when sheet is calculated
Code:
Private Sub Worksheet_Calculate()
    MsgBox "calculate"
End Sub
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Sorry EriK should stick to the basics is this correct

Private Sub Worksheet_Calculate(ByVal Target As Range)
If Target.Address = "$A$1" And Target.Value > 77 Then
MsgBox "calculate"
End If
End Sub
 
Upvote 0
HELP

I get procedure declaration does not match event or procedure having the same name.

when I do the simple code you gave me (1) that works but when I add the rest to it (2) it does not work

(1)
Private Sub Worksheet_Calculate()
MsgBox "calculate"
End Sub

(2)
Private Sub Worksheet_Calculate(ByVal Target As Range)
If Target.Address = "$A$1" And Target.Value > 77 Then
MsgBox "calculate"
End If
End Su
 
Upvote 0
change it to this:

Private Sub Worksheet_Calculate()

If Range("A1").Value > 77 Then
MsgBox ("Calculate")
PlayWAV
End If

End Sub

if it works, you can remove the MsgBox line.
good luck
 
Upvote 0
Re: HELP

I get procedure declaration does not match event or procedure having the same name.

when I do the simple code you gave me (1) that works but when I add the rest to it (2) it does not work

(1)
Private Sub Worksheet_Calculate()
MsgBox "calculate"
End Sub

(2)
Private Sub Worksheet_Calculate(ByVal Target As Range)
If Target.Address = "$A$1" And Target.Value > 77 Then
MsgBox "calculate"
End If
End Su
don't mess up with the code you get by default
calculate code doesn't have a "target"-argument
in the list at the upperright of your worksheetmodule-codepane you have several options
click them to see what comes out
 
Upvote 0

Forum statistics

Threads
1,216,217
Messages
6,129,567
Members
449,517
Latest member
Lsmich

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