返回列表 上一主題 發帖

EXCEL 發出聲音

回復 5# enoch
1.自訂函數
2.儲存格寫下公式如:  =IF(A1>5,PlaySound(TRUE),PlaySound(FALSE))
  1. Option Explicit
  2. Function PlaySound(Msg As Boolean)
  3.     Dim Spath As String, Cmd As String
  4.     Spath = "C:\Windows\Media\" & IIf(Msg, "Windows XP 啟動.wav", "Windows XP 登出音效.wav")
  5.     '存放音效的路徑: "C:\Windows\Media\"
  6.     Cmd = "C:\Program Files\Windows Media Player\wmplayer.exe " & Chr(34) & Spath & Chr(34)
  7.     '播放音效的程式: "C:\Program Files\Windows Media Player\wmplayer.exe " <-這裡要空一格
  8.     Shell Cmd, 0
  9. End Function
複製代碼

TOP

回復 9# enoch
你少了\
Function PlaySound(Msg As Boolean)
    Dim Spath As String, Cmd As String
    Spath = "C:\Windows\Media\" & IIf(Msg, "Windows 開香檳.wav", "Windows 通知.wav")
    '存放音效的路徑: "C:\Windows\Media\"
    Cmd = "C:\Program Files (x86)\Windows Media Player\wmplayer.exe " & Chr(34) & Spath & Chr(34)
    '播放音效的程式: "C:\Program Files\Windows Media Player\wmplayer.exe " <-這裡要空一格
    Shell Cmd, 0
End Function

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

回復 20# 自我感覺良好
你是在Excel 應用程式的VBA

  Call sndPlaySound32(ActiveWorkbook.Path & "\LoadIt.WAV", 0)

TOP

回復 23# 自我感覺良好
就在這主題理

TOP

        靜思自在 : 布施如播種,以歡喜心滋潤種子,才會發芽。
返回列表 上一主題