Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Moses
 
Posts: n/a
Default add a sound if Cell R6 value greater than 120

Hi, Does anyone know if I can add a .wav file if a cell value is greater than
120? If so can you offer any advice?
  #2   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default add a sound if Cell R6 value greater than 120

You need to use a VBA Event procedure. Right-click the sheet tab
and choose View Code. In the code module that appears on the VBA
Editor, paste the following code:

Option Explicit
Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Private Sub Worksheet_Calculate()
If Me.Range("A1").Value 10 Then
sndPlaySound32 "chimes.wav", 0
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
sndPlaySound32 "chimes.wav", 0
End If
End Sub

Change the reference to A1 to the cell you want to test, and
change "chimes.wav" to the sound file you wish to play. If the
file is not one of the standard Windows sound files, you'll need
to include the complete folder name of the file.


Cordially,
Chip Pearson
Pearson Software Consulting, LLC
www.cpearson




"Moses" wrote in message
...
Hi, Does anyone know if I can add a .wav file if a cell value
is greater than
120? If so can you offer any advice?



  #3   Report Post  
Posted to microsoft.public.excel.misc
Moses
 
Posts: n/a
Default add a sound if Cell R6 value greater than 120

Thank you Chip Pearson

It works but the sound plays regardless of the number entered. I changed it
to <120 but it still plays the sound even at 1 or 200?

"Chip Pearson" wrote:

You need to use a VBA Event procedure. Right-click the sheet tab
and choose View Code. In the code module that appears on the VBA
Editor, paste the following code:

Option Explicit
Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Private Sub Worksheet_Calculate()
If Me.Range("A1").Value 10 Then
sndPlaySound32 "chimes.wav", 0
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
sndPlaySound32 "chimes.wav", 0
End If
End Sub

Change the reference to A1 to the cell you want to test, and
change "chimes.wav" to the sound file you wish to play. If the
file is not one of the standard Windows sound files, you'll need
to include the complete folder name of the file.


Cordially,
Chip Pearson
Pearson Software Consulting, LLC
www.cpearson




"Moses" wrote in message
...
Hi, Does anyone know if I can add a .wav file if a cell value
is greater than
120? If so can you offer any advice?




  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default add a sound if Cell R6 value greater than 120

Chip has two routines that produce the chimes sound.

The worksheet_calculate routine would be used if the cell to check contained a
formula.

If you are changing the value in that cell by typing, you could modify the
second routine so that it checks to see what was entered. (I still used 10 as
the cutoff.)

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
If Target.Value 10 Then
sndPlaySound32 "chimes.wav", 0
End If
End If
End Sub

If the cell contains a formula, then I'd delete the worksheet_change event code.

If the cell changes because of typing, I'd delete the worksheet_calculate event
code.

If it could be either, then keep both.

Moses wrote:

Thank you Chip Pearson

It works but the sound plays regardless of the number entered. I changed it
to <120 but it still plays the sound even at 1 or 200?

"Chip Pearson" wrote:

You need to use a VBA Event procedure. Right-click the sheet tab
and choose View Code. In the code module that appears on the VBA
Editor, paste the following code:

Option Explicit
Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Private Sub Worksheet_Calculate()
If Me.Range("A1").Value 10 Then
sndPlaySound32 "chimes.wav", 0
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
sndPlaySound32 "chimes.wav", 0
End If
End Sub

Change the reference to A1 to the cell you want to test, and
change "chimes.wav" to the sound file you wish to play. If the
file is not one of the standard Windows sound files, you'll need
to include the complete folder name of the file.


Cordially,
Chip Pearson
Pearson Software Consulting, LLC
www.cpearson




"Moses" wrote in message
...
Hi, Does anyone know if I can add a .wav file if a cell value
is greater than
120? If so can you offer any advice?





--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
Moses
 
Posts: n/a
Default add a sound if Cell R6 value greater than 120

Thank you it works great!

"Dave Peterson" wrote:

Chip has two routines that produce the chimes sound.

The worksheet_calculate routine would be used if the cell to check contained a
formula.

If you are changing the value in that cell by typing, you could modify the
second routine so that it checks to see what was entered. (I still used 10 as
the cutoff.)

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
If Target.Value 10 Then
sndPlaySound32 "chimes.wav", 0
End If
End If
End Sub

If the cell contains a formula, then I'd delete the worksheet_change event code.

If the cell changes because of typing, I'd delete the worksheet_calculate event
code.

If it could be either, then keep both.

Moses wrote:

Thank you Chip Pearson

It works but the sound plays regardless of the number entered. I changed it
to <120 but it still plays the sound even at 1 or 200?

"Chip Pearson" wrote:

You need to use a VBA Event procedure. Right-click the sheet tab
and choose View Code. In the code module that appears on the VBA
Editor, paste the following code:

Option Explicit
Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Private Sub Worksheet_Calculate()
If Me.Range("A1").Value 10 Then
sndPlaySound32 "chimes.wav", 0
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
sndPlaySound32 "chimes.wav", 0
End If
End Sub

Change the reference to A1 to the cell you want to test, and
change "chimes.wav" to the sound file you wish to play. If the
file is not one of the standard Windows sound files, you'll need
to include the complete folder name of the file.


Cordially,
Chip Pearson
Pearson Software Consulting, LLC
www.cpearson




"Moses" wrote in message
...
Hi, Does anyone know if I can add a .wav file if a cell value
is greater than
120? If so can you offer any advice?




--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
Can a sound be inserted in a cell? nagao Excel Worksheet Functions 1 January 26th 06 09:17 PM
I want the greater number of 2 cells to show in a separate cell Ron Coderre Excel Discussion (Misc queries) 1 November 16th 05 09:22 PM
cell color index comparison MINAL ZUNKE New Users to Excel 1 June 30th 05 07:11 AM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM


All times are GMT +1. The time now is 04:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"