Randa
Randa

Reputation: 63

Playing a sound file when path is located in specific cell

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

Answers (3)

Scott Craner
Scott Craner

Reputation: 152585

Your cell reference is wrong.

If Application.CanPlaySounds Then
    Call sndPlaySound32(Range("A1"), 0)
End If

Upvotes: 0

cboden
cboden

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

TyBourque
TyBourque

Reputation: 628

It looks like you might be missing the value property try

Call sndPlaySound32(Cells([a1]).value, 0)

Upvotes: 0

Related Questions