How to Mute/Enable Windows Sounds whilst running VBA code

H

Hotbird

Most of the time, my PC runs silently. I am easily irritated by sounds of
windows opening, etc. etc. But exceptionally, I would like to be advised of
an unusual event by playing a Wav file through code. Is there a pair of
lines that I can add to enable before, and mute after the required sound has
played? Here is an example:

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


Public Sub PrinterCheck()

Dim int1as integer
Dim strWavFile As String

int1 = MsgBox("Ready to Print?", vbYesNoCancel)
boolNP = True
If int1 = 6 Then
strWavFile = ThisWorkbook.Path & "\sound1.wav"
boolNP = False
ElseIf int1 = 7 Then
strWavFile = ThisWorkbook.Path & "\sound2.wav"
End If
Call PlaySound(strWavFile, 0&, SND_ASYNC Or SND_FILENAME)

End Sub
 

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