2012-02-25 7 views

答えて

11

ここにWAVファイルの方法があります。通常のコードモジュールに**** this codeを置く:

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

Sub PlayTheSound(ByVal WhatSound As String) 
    If Dir(WhatSound, vbNormal) = "" Then 
     ' WhatSound is not a file. Get the file named by 
     ' WhatSound from the Windows\Media directory. 
     WhatSound = Environ("SystemRoot") & "\Media\" & WhatSound 
     If InStr(1, WhatSound, ".") = 0 Then 
      ' if WhatSound does not have a .wav extension, 
      ' add one. 
      WhatSound = WhatSound & ".wav" 
     End If 
     If Dir(WhatSound, vbNormal) = vbNullString Then 
      Beep   ' Can't find the file. Do a simple Beep. 
      Exit Sub 
     End If 
    Else 
     ' WhatSound is a file. Use it. 
    End If 

    sndPlaySound32 WhatSound, 0& ' Finally, play the sound. 
End Sub 

さて、あなたは上にそのルーチンを呼び出して、/ Mediaフォルダで見つかったファイル名で供給することによって、他のマクロを通じて任意のwavファイルを再生することができます:

Sub PlayIt() 
    Select Case Range("A1").Value 
     Case "good" 
      PlayTheSound "chimes.wav" 
     Case "bad" 
      PlayTheSound "chord.wav" 
     Case "great" 
      PlayTheSound "tada.wav" 
    End Select 
End Sub 

これで遊んでください。リンクを追加するための

Random Task List with AUDIO Reveal

+0

ありがとう:ここ

は、私はあなたが行う予定のような劇的な日のためにランダムな名前とタスクを明らかにするために、それがボタンに接続されていることを使用するサンプルファイルです、ブレット!私の悪い... –

+0

問題はない、それは化粧品の更新だった。 +1 btw – brettdj

関連する問題