اکسل

همه چیز درباره اکسل

اکسل

همه چیز درباره اکسل

۱ مطلب در تیر ۱۳۹۷ ثبت شده است

پخش صدا-فایل صوتی در اکسل

سه شنبه, ۱۹ تیر ۱۳۹۷، ۱۱:۴۵ ق.ظ

جهت پخش فایل صوتی در اکسل بایستی از API های ویندوز استفاده نمود که برای فراخوانی آنها از declare statement استفاده می شود لذا جهت شروع بایستی API مربوطه را فراخوانی نمائیم

Public Declare Function Sound32 _
    Lib "winmm.dll" _
    Alias "sndPlaySoundA" ( _
        ByVal lpszSoundName As String, _
        ByVal uFlags As Long) As Long

سپس در هر بخش از کد که نیاز به پخش یک فایل صوتی است تابع فوق را فراخوانی می کنیم مشابه زیر

Call sound32(WAVFile, snd_sync)

wavfile مسیر قرارگیری فایل است و گزینه بعدی نحوه پخش را مشخص می کند که پیش فرض snd_sync می باشد

Const SND_SYNC = &H0        ' (Default) Play the sound synchronously. Code execution
                            ' pauses until sound is complete.

Const SND_ASYNC = &H1       ' Play the sound asynchronously. Code execution
                            ' does not wait for sound to complete.

Const SND_NODEFAULT = &H2   ' If the specified sound is not found, do not play
                            ' the default sound (no sound is played).

Const SND_MEMORY = &H4      ' lpszSoundName is a memory file of the sound.
                            ' Not used in VBA/VB6.

Const SND_LOOP = &H8        ' Continue playing sound in a loop until the next
                            ' call to sndPlaySound.

Const SND_NOSTOP = &H10     ' Do not stop playing the current sound before playing
                            ' the specified sound.

نقل شده از

http://www.cpearson.com/excel/PlaySound.aspx

https://excel.tips.net/T006559_Conditionally_Playing_an_Audio_File.html

  • علیرضا باقری