返回列表 上一主題 發帖

EXCEL 發出聲音

修改了錯處, 但都是沒有聲音
不肯定是否電腦問題

但請問若想簡單一點, 內建除了BEEP 聲外
還會有其它聲音嗎?
或如果要連繼BEEP 兩聲, 應該如何呢?

TOP

方法太多了,簡單寫幾個常用的:
  1. Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrcommand As String) As Long
  2. Private Const Mic = "C:\Windows\Media\tada.wav"
  3. Sub op()
  4. mciExecute ("play " & Mic)
  5. End Sub

  6. Sub yy()
  7. cmd = "sndrec32 /play /close ""C:\Windows\Media\tada.wav"""
  8. Shell cmd, 6
  9. End Sub
  10. Sub xx()
  11. Beep
  12. Application.Wait (Now + TimeValue("0:00:1"))
  13. Beep
  14. End Sub
  15. Sub ww()
  16. Set oSa = CreateObject("SAPI.SpVoice")
  17.         oSa.Speak "misinput"
  18. End Sub
複製代碼

TOP

回復 12# oobird

突然想到,BEEP還可以編曲
  1. Declare Function Beep Lib "kernel32.dll" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

  2. Sub yy()
  3. f = Array(100, 523, 587, 659, 698, 784, 879, 987, 1030)
  4. d = Array(5, 3, 3, 0, 4, 2, 2, 0, 1, 2, 3, 4, 5, 5, 5, 0, 5, 3, 3, 0, 4, 2, 2, 0, 1, 3, 5, 5, 3, 0, 2, 2, 2, 2, 2, 3, 4, 0, 3, 3, 3, 3, 3, 4, 5, 0, 5, 3, 3, 0, 4, 2, 2, 0, 1, 3, 5, 5, 1)
  5. For i = 0 To UBound(d)
  6. Beep f(d(i)), 500
  7. Next
  8. End Sub
複製代碼

TOP

辛苦了各位的指教,
試過了Sub OP 但奇怪在電腦內找不到tada.wav,
改用其它C:\Windows\Media\內的WAV檔反而播唔到
而Sub YY  去到Shell cmd, 6 顯示找不到檔案

而這問題會同電腦有關嗎?
現時電腦是WIN7 64BIT,  若執行到後, 在其它WINXP 電腦又會否出現問題

最終希望可以播到在C:\Windows\Media\ 內建的wav檔

TOP

我終於發現錯在那裡, 原來在C:\Windows\Media\ 見到的中文檔案名稱. 原來是騙人
Windows 通知.wav 名稱, 原來真實檔案名稱叫 Windows Notify.wav
唔怪得播唔到,  
多謝各位耐心指教

TOP

本帖最後由 StanleyVic 於 2012-7-19 16:29 編輯

這個例子的提問太好了. 學習了...
我沒想過會用在Excel 去介定 對/錯.
平常都只會其他.. or msbox 提示..
不錯不錯..謝謝..
NeverTry , NeverNo !

TOP

解說得很詳細呢!

TOP

Play Sound.rar (40.73 KB) 附件是word要怎樣改成excel?
50 字節以內
不支持自定義 Discuz! 代碼

TOP

回復 18# 自我感覺良好
  1. Option Explicit
  2. 'API Class to take care of playing the file
  3. Public Declare Function sndPlaySound32 Lib "winmm.dll" _
  4. Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
  5.                         ByVal uFlags As Long) As Long
  6. Sub VBASound()
  7.     'Call Api to play LoadIt.wav witch is in the same folder as
  8.     'the active document!->ActiveWorkbook
  9.     Call sndPlaySound32(ActiveWorkbook.Path & "\LoadIt.WAV", 0)
  10.    
  11. End Sub
複製代碼

TOP


還是不能用﹗
幫我看一下那裡出錯了……回復 19# GBKEE
50 字節以內
不支持自定義 Discuz! 代碼

TOP

        靜思自在 : 脾氣嘴巴不好,心地再好也不能算是好人。
返回列表 上一主題