ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Mute/Enable Windows Sounds whilst running VBA code (https://www.excelbanter.com/excel-programming/305452-how-mute-enable-windows-sounds-whilst-running-vba-code.html)

Hotbird[_3_]

How to Mute/Enable Windows Sounds whilst running VBA code
 
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




All times are GMT +1. The time now is 04:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com