hi, Bert !
does this only work on/with *.wav files??
AFAIK for other comperssion formats (avi, mp3, ...) of sound files you can use the MCI functions
BTW, some this functions might require the path to the file in the (ancient) 8+3 filename format
this is an example of what how i use a UDF (called from my worksheets) like many others *IF* functions:
[A1] is the path to any folder containing the sound files
(i.e.) c:\documents and settings\<my profile\desktop\my music\
[A2] is the name of the file i want to be played if condition is met
(i.e.) led zeppelin - stairway to heaven.mp3
[A3] is the name of the file i want to be played if condition is NOT met
(i.e.) pink floyd - time.mp3
[A4] is a "flag" to play/stop the music (if its playing)
(i.e.) 0/1 or false/true
[A5] is the cell i want to be conditioned for play one of the files above
(i.e.) 20
the UDF is called (say in B5) using this sintax: - =Play_IF(a5,"=",26,a1&a2,a1&a3,a4)
in a standard code module, the required declarations, functions and procedures as follows...
if any doubt (or further information)... sould you please comment ?
regards,
hector.
' API functions entries '
Declare Function mciExecute Lib "winmm.dll" ( _
ByVal lpCommand As String) As Long
Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" ( _
ByVal LongPath As String, _
ByVal ShortPth As String, _
ByVal Buffer As Long) As Long
' UDF to obtain the ShortPath to the files '
Private Function StripName(ByVal LongName As String) As String
Dim Pos As Byte, ShortName As String
ShortName = Space(128)
Pos = GetShortPathName(LongName, ShortName, Len(ShortName))
StripName = LCase(Left(ShortName, Pos))
End Function
' this is the UDF called in worksheets cells ... '
' modify, adapt, ... as needed '
Function Play_IF(ByVal Compare As Variant, _
ByVal Operator As String, _
ByVal Condition As Variant, _
ByVal sndFileYes As String, _
Optional ByVal sndFileNo As String = "", _
Optional ByVal Action As Boolean = True) As String
Dim Command As String: Command = IIf(Action, "play ", "stop ")
If Evaluate("""" & Compare & """" & Operator & """" & Condition & """") Then
If Dir(sndFileNo) < "" Then mciExecute "stop " & StripName(sndFileYes)
If Dir(sndFileYes) < "" Then mciExecute Command & StripName(sndFileYes)
Play_IF = "Condition met !!!"
ElseIf Dir(sndFileNo) < "" Then
If Dir(sndFileYes) < "" Then mciExecute "stop " & StripName(sndFileYes)
mciExecute Command & StripName(sndFileNo)
Play_IF = "Condition failed !!!"
Else: Play_IF = "Condition failed !!!"
End If
End Function