View Full Version : 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:think:
Charlize
03-04-2008, 02:59 AM
You could use MsgBox "Deze invoer is onjuist",vbCriticalI believe it uses the sounds that are declared within your windows OS.
Charlize
anandbohra
03-04-2008, 04:40 AM
try beep
eg
sub msgbeep()
msgbox "blah blah blah",vbokonly
beep
end sub
Charlize
03-04-2008, 04:51 AM
Variation with the music you want. You can record your own wav files if you want.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 SubCharlize
I think it doens't work because i use it on a worksheet and not on a module.
Ger
Bob Phillips
03-04-2008, 05:32 AM
It is not that, it works fine triggered by the change event. Sure you don't have sound muted?
Charlize
03-04-2008, 06:08 AM
I think it doens't work because i use it on a worksheet and not on a module.
GerPrivate Sub Worksheet_Change(ByVal Target As Range)
If [ge141] <> [ge142] Then
Call PlaySound
End If
End Suband PlaySound is located in a module.
Charlize
ps.: maybe check your cables, muted or not, volume, ... do you have a soundcard ?
variation :
Private Sub Worksheet_Change(ByVal Target As Range)
If [ge141] <> [ge142] Then
Call PlaySound("c:\data\mysounds\tada.wav")
End If
End Sub
in a module you place :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
Ok.
Now it works fine.
Thanks
Bob Phillips
03-04-2008, 08:15 AM
So what was the problem?
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.