Sound

The Beep command is about as good as it gets.
Not all systems support sound you can check though

If Application.CanPlaySound = True Then 
End If

Private Declare Function PlaySound Lib "winmm.dll" _ 
  Alias "PlaySoundA" (ByVal lpszName As String, _
  ByVal hModule As Long, ByVal dwFlags As Long) As Long

Private Declare Function mciExecute Lib "winmm.dll" _
  (ByVal lpstrCommand As String) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim SoundFile As Variant

Sub GetFile() 
    ActiveSheet.Shapes("StopButton").Visible = False
    Filters = "Sound Files (*.mid; *.wav), *.mid; *.wav"
    SoundFile = Application.GetOpenFilename(Filters)
    If SoundFile = False Then Exit Sub
    Select Case UCase(Right(SoundFile, 3))
        Case "MID"
            mciExecute ("play " & SoundFile)
            ActiveSheet.Shapes("StopButton").Visible = True
        Case "WAV"
            Call PlaySound(SoundFile, 0&, SND_ASYNC Or SND_FILENAME)
        Case Else
    End Select
End Sub

Sub StopMIDI() 
    mciExecute ("stop " & SoundFile)
    ActiveSheet.Shapes("StopButton").Visible = False
End Sub


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext