Consulting

Results 1 to 11 of 11

Thread: Solved: sound with msgbox

  1. #1
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location

    Solved: sound with msgbox

    Is it possible to make a sound if the msgbox appears?

    Private Sub Worksheet_Change(ByVal Target As Range)

    If [ge141] <> [ge142] Then
    MsgBox "Deze invoer is onjuist"
    End If

    End Sub

    Ger

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    You could use [VBA]MsgBox "Deze invoer is onjuist",vbCritical[/VBA]I believe it uses the sounds that are declared within your windows OS.

    Charlize

  3. #3
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    Sorry, no sound.

    Ger

  4. #4
    VBAX Mentor anandbohra's Avatar
    Joined
    May 2007
    Location
    Mumbai
    Posts
    313
    Location
    try beep


    eg

    [vba]sub msgbeep()
    msgbox "blah blah blah",vbokonly
    beep

    end sub
    [/vba]
    Always Mark your Thread as Solved the moment u got acceptable reply (located under Thread tools)
    Practice this & save time of others in thinking for unsolved thread

  5. #5
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Variation with the music you want. You can record your own wav files if you want.[VBA]Option Explicit
    Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Sub PlaySound()
    Dim v_mysound As String
    v_mysound = "c:\data\mysounds\tada.wav"
    If Application.CanPlaySounds Then
    Call sndPlaySound32(v_mysound, 1)
    MsgBox "Give me some music ..."
    Else
    MsgBox "Sorry no music"
    End If
    End Sub[/VBA]Charlize

  6. #6
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    I think it doens't work because i use it on a worksheet and not on a module.

    Ger

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is not that, it works fine triggered by the change event. Sure you don't have sound muted?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Quote Originally Posted by Ger
    I think it doens't work because i use it on a worksheet and not on a module.

    Ger
    [vba]Private Sub Worksheet_Change(ByVal Target As Range)
    If [ge141] <> [ge142] Then
    Call PlaySound
    End If
    End Sub[/vba]and PlaySound is located in a module.

    Charlize

    ps.: maybe check your cables, muted or not, volume, ... do you have a soundcard ?

    variation :
    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    If [ge141] <> [ge142] Then
    Call PlaySound("c:\data\mysounds\tada.wav")
    End If
    End Sub[/VBA]
    in a module you place :[VBA]Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Sub PlaySound(v_mysound As String)
    If Application.CanPlaySounds Then
    Call sndPlaySound32(v_mysound, 1)
    MsgBox "Give me some music ..."
    Else
    MsgBox "Sorry no music"
    End If
    End Sub[/VBA]

  9. #9
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    Ok.

    Now it works fine.

    Thanks

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    So what was the problem?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    VBAX Contributor
    Joined
    Feb 2008
    Posts
    193
    Location
    The path to the sound file in the worksheet didn't work. if i put it in the module it works fine.
    (worksheet)
    Private Sub Worksheet_Change(ByVal Target As Range)

    If [ge119] <> [ge120] Then
    Call PlaySound
    End If

    End Sub

    (module)
    Option Explicit
    Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Sub PlaySound()
    Dim v_mysound As String
    v_mysound = "j:\zuid\zml\vpm\jaarplanner vpm\52.wav"
    If Application.CanPlaySounds Then
    Call sndPlaySound32(v_mysound, 1)
    MsgBox "Deze invoer is niet correct"
    Else
    MsgBox "Sorry no music"
    End If
    End Sub


    Ger

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •