返回列表 上一主題 發帖

[發問] 偵錯沒問題,就是無法執行

回復 5# wells330

放錯工作表模組
學海無涯_不恥下問

TOP

WINDWOS 錄音機
C:\Windows\system32\SoundRecorder.exe
但是,錄音機能用來播放音效嗎?
學海無涯_不恥下問

TOP

播放曲目的對應寫在第3列

附件請解壓縮到電腦後再開啟
一般模組
  1. Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrcommand As String) As Long
  2. Sub op(mypath)
  3. On Error Resume Next
  4. mciExecute "play " & mypath
  5. End Sub
複製代碼
工作表模組
  1. Private Sub Worksheet_Calculate()
  2. For Each a In [B1:D1]
  3.    If a > a.Offset(1, 0) Then
  4.       mypath = ThisWorkbook.Path & "\" & a.Offset(2, 0)
  5. Application.OnTime Now + TimeValue("00:00:03") * i, "'op " & Chr(34) & mypath & Chr(34) & "'"
  6. i = i + 1
  7. Application.OnTime Now + TimeValue("00:00:03") * i, "'op " & Chr(34) & mypath & Chr(34) & "'"
  8. i = i + 1
  9.     End If
  10. Next
  11. End Sub
複製代碼
PlaySound.rar (90.72 KB)
學海無涯_不恥下問

TOP

B1:D2我用RANDBETWEEN函數
第三列就直接輸入該欄條件成立要播放的曲目
按F9重算就會播放
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2011-5-3 22:32 編輯

另一個API函數用法sndPlaySound
一般模組
  1.       Private Declare Function sndPlaySound Lib "winmm.dll" Alias _
  2.       "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  3.       Function SndPlay(Pathname As String) As Long
  4.           SndPlay = sndPlaySound(Pathname, SND_ASYNC)
  5.       End Function
複製代碼
工作表模組
  1. Private Sub Worksheet_Calculate()
  2. For Each a In [B1:D1]
  3.    If a > a.Offset(1, 0) Then
  4.       mypath = ThisWorkbook.Path & "\" & a.Offset(2, 0)
  5. Application.OnTime Now + TimeValue("00:00:03") * i, "'SndPlay " & Chr(34) & mypath & Chr(34) & "'"
  6. i = i + 1
  7. Application.OnTime Now + TimeValue("00:00:03") * i, "'SndPlay " & Chr(34) & mypath & Chr(34) & "'"
  8. i = i + 1
  9.     End If
  10. Next
  11. End Sub
複製代碼
B1:D2輸入公式
=RAND()
B3:D3輸入音效檔名(含副檔名)
按F9重算
WIN XP+2003版
WIN 7+2010版
測試通過
PlaySound.zip (85.04 KB)
學海無涯_不恥下問

TOP

        靜思自在 : 站在半路,比走到目標更辛苦。
返回列表 上一主題