path位于特定单元格中时播放声音文件
在运行macros时,我想播放声音。 但声音将根据条件确定。 声音文件位于单元格A1中。 为什么我不能获取命令来读取单元格中的文件path? 任何帮助,将不胜感激。 (我知道这对你们中的一些人来说很容易,所以请不要阻止我。)
' COMMUNICATION: Play sound file located in cell a1 If Application.CanPlaySounds Then Call sndPlaySound32(Cells([a1]), 0) End If
sndPlaySound32是一个API函数。 所以你必须先申报。 放在你的VBA模块的顶部:
Declare Function sndPlaySound32 Lib "winmm.dll" Alias _ "sndPlaySoundA" (ByVal lpszSoundName As String, _ ByVal uFlags As Long) As Long
看起来你可能会错过价值属性尝试
Call sndPlaySound32(Cells([a1]).value, 0)
你的单元格引用是错误的。
If Application.CanPlaySounds Then Call sndPlaySound32(Range("A1"), 0) End If