2012年4月24日 星期二

如何使用Excel VBA發出聲音(警訊聲)

用VBA做程式交易時
常常需要出現訊號時 讓程式自動發出警示聲響

以下為vbaexpress.com所提供的程式碼:



Option Explicit 

 'API Class to take care of playing the file
Public Declare Function sndPlaySound32 Lib "winmm.dll" _ 
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _ 
ByVal uFlags As Long) As Long 

Sub VBASound() 
     'Call Api to play LoadIt.wav which is in the same folder as
     'the active document!
    Call sndPlaySound32(ActiveDocument.Path & "\LoadIt.WAV", 0) 
End Sub 





(出處:http://www.vbaexpress.com/kb/getarticle.php?kb_id=461)


而需要的WAV檔素材
可以至以下網站下載

沒有留言:

張貼留言