2012-02-25 13 views

Respuesta

11

Aquí hay una manera para los archivos WAV. Ponga ** ** this code en un módulo de código normal:

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 

Ahora, puede reproducir cualquier archivo WAV a través de cualquier otro macro llamando a la rutina anterior y alimentación en cualquier nombre de archivo que se encuentra en la carpeta/Medios:

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 

Juega con eso.

Aquí es un archivo de ejemplo donde uso que se revele de forma espectacular nombres al azar y tareas para el día, que se adjunta a un botón que va a hacer:

Random Task List with AUDIO Reveal

+0

Gracias por añadir el enlace ¡Brett! Mi mal ... –

+0

No hay problema, era más una actualización cosmética. +1 por cierto – brettdj

Cuestiones relacionadas