Help for Heroes
New Member
- Joined
- Apr 7, 2013
- Messages
- 1
Hi, I'm trying to add a .wav sound to all cells in a column if it equals "! ALERT !". I have created a macro and added the following code:
Private DeclareFunction PlaySound Lib "winmm.dll" _<o
></o
>
Alias "PlaySoundA" (ByVal lpszNameAs String, _<o
></o
>
ByVal hModule As Long, ByVal dwFlags As Long)As Long<o
></o
>
<o
> </o
>
Const SND_SYNC = &H0<o
></o
>
Const SND_ASYNC = &H1<o
></o
>
Const SND_FILENAME = &H20000<o
></o
>
<o
></o
>
Sub PlayWAV()<o
></o
>
WAVFile = ThisWorkbook.Path &"\Windows Exclamation.wav"<o
></o
>
Call PlaySound(WAVFile, 0&, SND_ASYNCOr SND_FILENAME)<o
></o
>
End Sub<o
></o
>
<o
> </o
>
<o
> </o
>
Private SubWorksheet_Change(ByVal Target As Range)<o
></o
>
<o
> </o
>
Threshold = "! ALERT !"<o
></o
>
If Range("AZ4").Value = ThresholdThen PlayWAV<o
></o
>
<o
> </o
>
End Sub<o
></o
>
This works for the first cell in the column and I'm assuming I'll to add a loop within it to apply the same to the rest of the column cells. I would also like to reference .wav files in other files but using c:\BERT\BEAM-ME-UP-SCOTTY doesn't work? How do I do this and is it something to do with the FILEPATH? This is my first macro and I would appreciate help in achieving this, please help. Many thanks J
Private DeclareFunction PlaySound Lib "winmm.dll" _<o
Alias "PlaySoundA" (ByVal lpszNameAs String, _<o
ByVal hModule As Long, ByVal dwFlags As Long)As Long<o
<o
Const SND_SYNC = &H0<o
Const SND_ASYNC = &H1<o
Const SND_FILENAME = &H20000<o
<o
Sub PlayWAV()<o
WAVFile = ThisWorkbook.Path &"\Windows Exclamation.wav"<o
Call PlaySound(WAVFile, 0&, SND_ASYNCOr SND_FILENAME)<o
End Sub<o
<o
<o
Private SubWorksheet_Change(ByVal Target As Range)<o
<o
Threshold = "! ALERT !"<o
If Range("AZ4").Value = ThresholdThen PlayWAV<o
<o
End Sub<o
This works for the first cell in the column and I'm assuming I'll to add a loop within it to apply the same to the rest of the column cells. I would also like to reference .wav files in other files but using c:\BERT\BEAM-ME-UP-SCOTTY doesn't work? How do I do this and is it something to do with the FILEPATH? This is my first macro and I would appreciate help in achieving this, please help. Many thanks J
Last edited: