ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding Sound to Program (https://www.excelbanter.com/excel-programming/327982-adding-sound-program.html)

Carlton Patterson

Adding Sound to Program
 
Hi all,

I don't know if I should be posting on Google groups or here, so forgive
me if I'm not following protocol.

Anyway, can someone show me how to add/play a sound to the following:

Private Sub Worksheet_Calculate()
If Range("I1").Value 0 Then
Beep
'or msgbox
'or play sound
'or send email
'or whatever
End If
End Sub

You'll notice that there is a "Beep" in the program but it doesn't work.


Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***

Bob Phillips[_6_]

Adding Sound to Program
 
Beep should work (bit naff, but works). Are you sure you don't have sound
muted?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Carlton Patterson" wrote in message
...
Hi all,

I don't know if I should be posting on Google groups or here, so forgive
me if I'm not following protocol.

Anyway, can someone show me how to add/play a sound to the following:

Private Sub Worksheet_Calculate()
If Range("I1").Value 0 Then
Beep
'or msgbox
'or play sound
'or send email
'or whatever
End If
End Sub

You'll notice that there is a "Beep" in the program but it doesn't work.


Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***




Carlton Patterson

Adding Sound to Program
 
Hi Bob,

I'm positive mate.

Its a little strange because I'm sure it beeped the first time I
executed it.

Carlton

*** Sent via Developersdex http://www.developersdex.com ***

Bob Phillips[_6_]

Adding Sound to Program
 
Hi Carlton,

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


Private Sub Workbook_Calculate()
If Range("I1").Value 0 Then
PlayWavFile "C:\Windows\Media\Microsoft Office 2000\Chimes.wav"

End If
End Sub


Public Function PlayWavFile(WavFile As String) As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
PlaySound WavFile, 0, SND_ASYNC Or SND_FILENAME
PlayWavFile = ""
End Function

If this doesn't work, check mute again <g

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Carlton Patterson" wrote in message
...
Hi Bob,

I'm positive mate.

Its a little strange because I'm sure it beeped the first time I
executed it.

Carlton

*** Sent via Developersdex http://www.developersdex.com ***




Carlton Patterson

Adding Sound to Program
 
Hi Bob,

I managed to get a Beep when I pasted this program into excel. So I
don't understand why I the simple program I pasted earlier won't work,
uhmmmmm....

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column 2 Then Exit Sub 'A or B okay
If Cells(Target.Row, 1) < Cells(Target.Row, 2) Then
Beep
End If
End Sub


Carlton

*** Sent via Developersdex http://www.developersdex.com ***

Bob Phillips[_6_]

Adding Sound to Program
 
LOL.

There is no Workbook_Calculate event, it is Worksheet_Calculate!

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Carlton Patterson" wrote in message
...
Hi Bob,

I managed to get a Beep when I pasted this program into excel. So I
don't understand why I the simple program I pasted earlier won't work,
uhmmmmm....

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column 2 Then Exit Sub 'A or B okay
If Cells(Target.Row, 1) < Cells(Target.Row, 2) Then
Beep
End If
End Sub


Carlton

*** Sent via Developersdex http://www.developersdex.com ***




Carlton Patterson

Adding Sound to Program
 
Hee hee,

I should've seen that.

Cheers mate.

Carlton

*** Sent via Developersdex http://www.developersdex.com ***

Carlton Patterson

Adding Sound to Program
 
Hello Bob,

while on the subject of sounds, is it possible to program excel to play
a sound as a value increments?

For example, lets say I have a cell with the current value of 1, I would
like to hear a single beep. Then, if the value goes up to 2 I would like
to hear another single beep and so on... Is that possible?

Cheers mate.

Carlton

*** Sent via Developersdex http://www.developersdex.com ***

Bob Phillips[_6_]

Adding Sound to Program
 
Hi Carlton,

easy enough


Private Sub Worksheet_Calculate()
Static prevValue
If Range("I1").Value prevValue Then
Beep
prevValue = Range("I1").Value
End If
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Carlton Patterson" wrote in message
...
Hello Bob,

while on the subject of sounds, is it possible to program excel to play
a sound as a value increments?

For example, lets say I have a cell with the current value of 1, I would
like to hear a single beep. Then, if the value goes up to 2 I would like
to hear another single beep and so on... Is that possible?

Cheers mate.

Carlton

*** Sent via Developersdex http://www.developersdex.com ***




Carlton Patterson

Adding Sound to Program
 
Hi Bob,


Thats great mate.

Cheers mate

Carlton

*** Sent via Developersdex http://www.developersdex.com ***

Tom Ogilvy

Adding Sound to Program
 
Paste this program in a new module

Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration
As Long) As Long

Sub Beep1()
Dim num As Single
Dim num1 As Long
Dim numLoops As Single
num = 10
NumSeconds = 4
numLoops = (NumSeconds * num * 2) / 2
If numLoops < 1 Then
numLoops = 1
End If
num1 = 1000 / (num * 2)

For i = 1 To numLoops
'DoEvents
Beep 500, num1
'DoEvents
Beep 10000, num1
'DoEvents
Next
End Sub


-----------------------------------
Execute/run the Beep1 macro.

While it is running see where the beep is coming from - From your sound
card, or from your system unit itself?

Playsound should come from your sound card, but I would expect beep to come
from the built in speaker of your computer.

--
Regards,
Tom Ogilvy

"Carlton Patterson" wrote in message
...
Hi Bob,


Thats great mate.

Cheers mate

Carlton

*** Sent via Developersdex http://www.developersdex.com ***




Steve Schroeder

Adding Sound to Program
 
If a worksheet beeps, but no one is around to hear it, does it still make a
sound?

"Carlton Patterson" wrote in message
...
Hi all,

I don't know if I should be posting on Google groups or here, so forgive
me if I'm not following protocol.

Anyway, can someone show me how to add/play a sound to the following:

Private Sub Worksheet_Calculate()
If Range("I1").Value 0 Then
Beep
'or msgbox
'or play sound
'or send email
'or whatever
End If
End Sub

You'll notice that there is a "Beep" in the program but it doesn't work.


Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***




Bob Phillips[_6_]

Adding Sound to Program
 
Schrodinger's spreadsheet? What sort of animal is that?

Bob


"Steve Schroeder" wrote in message
...
If a worksheet beeps, but no one is around to hear it, does it still make

a
sound?

"Carlton Patterson" wrote in message
...
Hi all,

I don't know if I should be posting on Google groups or here, so forgive
me if I'm not following protocol.

Anyway, can someone show me how to add/play a sound to the following:

Private Sub Worksheet_Calculate()
If Range("I1").Value 0 Then
Beep
'or msgbox
'or play sound
'or send email
'or whatever
End If
End Sub

You'll notice that there is a "Beep" in the program but it doesn't work.


Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***






Steve Schroeder

Adding Sound to Program
 
Don't make me hurt ya now :-P

"Bob Phillips" wrote in message
...
Schrodinger's spreadsheet? What sort of animal is that?

Bob


"Steve Schroeder" wrote in message
...
If a worksheet beeps, but no one is around to hear it, does it still

make
a
sound?

"Carlton Patterson" wrote in message
...
Hi all,

I don't know if I should be posting on Google groups or here, so

forgive
me if I'm not following protocol.

Anyway, can someone show me how to add/play a sound to the following:

Private Sub Worksheet_Calculate()
If Range("I1").Value 0 Then
Beep
'or msgbox
'or play sound
'or send email
'or whatever
End If
End Sub

You'll notice that there is a "Beep" in the program but it doesn't

work.


Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***








Bob Phillips[_6_]

Adding Sound to Program
 
I said Schrodinger's, not Schroeder's, Ernst not Steve ;-)


"Steve Schroeder" wrote in message
...
Don't make me hurt ya now :-P

"Bob Phillips" wrote in message
...
Schrodinger's spreadsheet? What sort of animal is that?

Bob


"Steve Schroeder" wrote in message
...
If a worksheet beeps, but no one is around to hear it, does it still

make
a
sound?

"Carlton Patterson" wrote in message
...
Hi all,

I don't know if I should be posting on Google groups or here, so

forgive
me if I'm not following protocol.

Anyway, can someone show me how to add/play a sound to the

following:

Private Sub Worksheet_Calculate()
If Range("I1").Value 0 Then
Beep
'or msgbox
'or play sound
'or send email
'or whatever
End If
End Sub

You'll notice that there is a "Beep" in the program but it doesn't

work.


Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***









Carlton Patterson

Adding Sound to Program
 
Hi Tom,

Thanks for the program, however the following statement is highlighted
in red followed by this error message:

Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal
dwDuration
As Long) As Long


Compile Error:

Expected: list separator or )

Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***

Bob Phillips[_6_]

Adding Sound to Program
 
That should all be one line.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Carlton Patterson" wrote in message
...
Hi Tom,

Thanks for the program, however the following statement is highlighted
in red followed by this error message:

Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal
dwDuration
As Long) As Long


Compile Error:

Expected: list separator or )

Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***




Carlton Patterson

Adding Sound to Program
 
Bob,

Thanks a lot mate.

Cheers

Carlton

*** Sent via Developersdex http://www.developersdex.com ***

Carlton Patterson

Adding Sound to Program
 
Hi Bob,

I tried to add sound to the following excel program however I keep on
getting an error message saying "Sub or Function not defined". Can you
help?

Private Sub Worksheet_Calculate()
Static prevValue
If Range("I1").Value prevValue Then
PlayWavFile "C:\Windows\Media\Windows XP Print complete"
prevValue = Range("I1").Value
End If
End Sub

Cheers

Carlton



*** Sent via Developersdex http://www.developersdex.com ***


All times are GMT +1. The time now is 02:24 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com