so...be doing a lot of reading....and i can't figure it out...
Found this code (and other slightly different version) - but this seems to be the closest to actually working )
It works fine and will play any .wav file in "C:\Windows\Media\", but i can't seem to get it to play a sound located elsewhere.
I moved it the the desktop for ease while test, but ultimately it will be playing a file from a network location.
Found this code (and other slightly different version) - but this seems to be the closest to actually working )
VBA Code:
Option Explicit
'Declaration for Win10 and Office 64 bit
Public Declare PtrSafe Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub TestPlayWavFileAPI()
'run this to play a sound wave (.wav) file
Dim sPath As String
'path to wave file - replace with your own
sPath = "C:\Windows\Media\Ring06.wav"
'sPath = "C:\Users\Username\desktop\1.wav"
'test the no-wait feature
PlayWavFileAPI sPath, False
MsgBox "This message box appears during the sound"
'test the wait feature
PlayWavFileAPI sPath, True
MsgBox "This message appears only after the sound stops"
End Sub
Function PlayWavFileAPI(sPath As String, Wait As Boolean) As Boolean
'API declaration of sndPlaySound is modified for 64 bit windows
'and tests well in Excel 2019 vba version 7.1.
'For earlier versions it might be necessary to remove the word PtrSafe
'from the declaration, or to consider another format.
'make sure file exists
If Dir(sPath) = "" Then
Exit Function
End If
If Wait Then
'hold up follow-on code until sound complete
sndPlaySound sPath, 0
Else
'continue with code run while sound is playing
sndPlaySound sPath, 1
End If
End Function
Sub btn2_Click()
Call TestPlayWavFileAPI
End Sub
It works fine and will play any .wav file in "C:\Windows\Media\", but i can't seem to get it to play a sound located elsewhere.
I moved it the the desktop for ease while test, but ultimately it will be playing a file from a network location.