Hi, I am using the below code to play a .wav file which acts like a wake up alarm. The .wav file is 8 mins long so that I definitely wake up. But while the alarm/.wav is playing I would like to be able to mute the sound for 30 seconds if the spacebar is pressed (so that I have time to wake up and mute the sound myself).
I am using this code to play the .wav file:
And I have found this code which makes it possible to mute sound, but I'm not sure how to link it to pressing the spacebar, and only enable it whilst the wav file is playing, and to get the sound to unmute automatically after 30 seconds.
Any help would be appreciated, Thanks!
I am using this code to play the .wav file:
Rich (BB code):
Function Alarm(Cell, Condition)
Dim WAVFile As String
'Dim fileaudio As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
On Error GoTo ErrHandler
If Evaluate(Cell.Value & Condition) Then
WAVFile = ThisWorkbook.Path & "\Fire Alarm.wav" 'Edit this statement
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function
And I have found this code which makes it possible to mute sound, but I'm not sure how to link it to pressing the spacebar, and only enable it whilst the wav file is playing, and to get the sound to unmute automatically after 30 seconds.
Rich (BB code):
Option Explicit
Const VK_VOLUME_MUTE = &HAD
Const VK_VOLUME_DOWN = &HAE
Const VK_VOLUME_UP = &HAF
#If VBA7 Then
Private Declare PtrSafe Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
#Else
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
#End If
Sub VolUp()
keybd_event VK_VOLUME_UP, 0, 1, 0
keybd_event VK_VOLUME_UP, 0, 3, 0
End Sub
Sub VolDown()
keybd_event VK_VOLUME_DOWN, 0, 1, 0
keybd_event VK_VOLUME_DOWN, 0, 3, 0
End Sub
Sub VolToggle()
keybd_event VK_VOLUME_MUTE, 0, 1, 0
End Sub
Any help would be appreciated, Thanks!