2012-02-25 9 views
5

का उपयोग कर एक लहर फ़ाइल या ध्वनि फ़ाइल कैसे खेलें मेरे पास एक लहर फ़ाइल है जिसे मैं वीबीए का उपयोग करके खेलना चाहता हूं। कृपया बटन बनाने के लिए मेरी मदद करें, जब वेव फ़ाइल पर क्लिक करते हैं।वीबीए

उत्तर

11

यहां डब्ल्यूएवी फाइलों के लिए एक तरीका है। एक नियमित रूप से कोड मॉड्यूल में रखो ** 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 

अब, आप किसी अन्य मैक्रो के माध्यम से किसी भी 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 बीटीडब्ल्यू – brettdj