0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【VBA】VBAでwavファイル(サウンド)を再生する。

Last updated at Posted at 2020-04-02

メモとして残します。

■やり方

標準コードに定義

Public 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

Public Sub PlaySound()
    Dim SoundFile As String, rc As Long
    SoundFile = Chr(34) & "C:\Windows\Media\Windows Critical Stop.wav" & Chr(34)
    rc = mciSendString("Close " & SoundFile, "", 0, 0)
    rc = mciSendString("Open " & SoundFile, "", 0, 0)
    rc = mciSendString("Play " & SoundFile & "", "", 0, 0)
End Sub

■さいごに

上記は非同期での再生で且つ、対象ファイルのプロセスを最初クローズしてから再生するため、短いSEを流すのに最適です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?