View Full Version : sound with vba
chungtinhlak
02-22-2009, 11:26 AM
Is it possible to have a sound in windows play when a condition match? Like if a certain cell = x, then a sound will play?
thanks
omnibuster
02-22-2009, 11:35 AM
Sub Bp()
Range("A1").Select
If Range("A1").Value = 0 Then
Beep
End If
End Sub
Kenneth Hobs
02-22-2009, 11:53 AM
The method depends on what sound you want and what is the trigger event?
You can trigger by a Change event on a sheet. Right click the sheet tab, View Code, and paste this. It will say what changed in Column A.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then Target.Speak
End Sub
chungtinhlak
02-22-2009, 12:16 PM
thank you, i have another question, so i have five different if statemetn, if it's true, a sound will play, if they're all true, all 5 will play, can i set it to wait for one sound to be done then the other sound?
chungtinhlak
02-22-2009, 12:17 PM
by the way, beep is one, where do i go to find other sounds?
Paul_Hossler
02-22-2009, 12:43 PM
Another way is play a WAV file
Down side is that you need the WAV files available on the computer, but the upside is that the web is FULL of wav files from movies, etc.
You could use the Recorder and make your own WAVs if you want to
The example below plays 2 WAVs on after the other
Option Explicit
Option Private Module
'It is very simple to have your macro code play a WAV file. First, add a Windows95
'API declaration at the top of your code module:
'Then, call the function, passing it the name of the WAV file you want to play:
Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub Play(SoundFile As String)
Call sndPlaySound32(SoundFile, 0)
End Sub
Sub SpaceOddessy()
Call Play("c:\Test\2001 - I'm Sorry Dave.wav")
Call Play("c:\Test\2001 - Human Error.wav")
End Sub
Paul
Kenneth Hobs
02-22-2009, 12:47 PM
Again, what are the IF conditions and what did you want to happen? You need to trigger off one of the dependent cells that gets changed rather than a Calculate event that fires when a formula changes value. What sounds to play, midi, wav, mpg, etc.?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.