Reputation: 63
When running a macro I would like to play a sound. However the sound will be determined based on conditions. The sound file is located in cell A1. Why can I not get the command to read the file path in the cell? Any help would be appreciated. (I realize this is very easy for some of you so please don't block me.)
' COMMUNICATION: Play sound file located in cell a1
If Application.CanPlaySounds Then
Call sndPlaySound32(Cells([a1]), 0)
End If
Upvotes: 0
Views: 335
Reputation: 152585
Your cell reference is wrong.
If Application.CanPlaySounds Then
Call sndPlaySound32(Range("A1"), 0)
End If
Upvotes: 0
Reputation: 823
sndPlaySound32 is an API function. So you have to declare it first. Put on top of your VBA module:
Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Upvotes: 1
Reputation: 628
It looks like you might be missing the value property try
Call sndPlaySound32(Cells([a1]).value, 0)
Upvotes: 0