読者です 読者をやめる 読者になる 読者になる

excelVBAで音を鳴らす

APIを使う

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Sub Sample2()
    Dim SoundFile As String, rc As Long
    SoundFile = "C:\Windows\Media\tada.wav"
    If Dir(SoundFile) = "" Then
        MsgBox SoundFile & vbCrLf & "がありません。", vbExclamation
        Exit Sub
    End If
    rc = mciSendString("Play " & SoundFile, "", 0, 0)
End Sub

サウンドデータはC:\Windows\Media\にいっぱいあるよ

ネタ元