How can I use VBA to play sounds in Windows 11? The code below worked in Windows 10 but does nothing in Windows 11.
Code execution does not throw an error.
I verified the sound file referenced in the code exists in Windows 11 and played it back successfully in VLC but nothing plays when this VBA code is run.
#If VBA7 Then ' 64-bit MS Office
Private Declare PtrSafe Function sndPlaySound32bit Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As LongPtr) As LongPtr
#Else ' 32-bit MS Office
Private Declare Function sndPlaySound32bit Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As LongPtr) As LongPtr
#End If
Public Sub PlaySound()
sndPlaySound32bit "C:\Windows\Media\Speech On.wav", "&H1" ' should be &H1 (without double-quotes; see answer from @Gustav
End Sub