View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.misc
David McRitchie
 
Posts: n/a
Default sound clip as a result of conditional formatting... ?

Hi John, (this is old from Dec 3rd to 5th but it looked like you are waiting for an answer)

You did not really describe what you wanted to do.

What Chip gave you was macro code that you can invoke a macro
to play a chime (which you asked for), but you can't use it in Conditional Formatting.
You can read more about Conditional Formatting in
http://www.mvps.org/dmcritchie/excel/condfmt.htm
but be aware that playing a chime is not formatting so you can't
use Conditional Formatting.

Since you want a chime it is probably to be used as an error condition
that you want them to correct the data just entered in error, in which case you
probably want to look at cell validation. (try the Flash presentation first)
http://www.mvps.org/dmcritchie/excel/validation.htm
http://www.contextures.com/tiptech.html -- Data Validation
http://www.datapigtechnologies.com/ExcelMain.htm -- Data Validation [Flash presentation]
Additional places to find Excel Tutorials on
http://www.mvps.org/dmcritchie/excel....htm#tutorials

If you want to do something yourself using a Change Event macro

Install Chip's code at the TOP of a standard module -- a new module in your personal.xls would be fine
as the declarations above the SUB should be at the top. I'll change the name
from AAA to chimes. If you have never installed a macro in your personal.xls
see http://www.mvps.org/dmcritchie/excel/getstarted.htm
additional help in calling a function or a macro in
http://www.mvps.org/dmcritchie/excel/install.htm

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

Sub chimes()
sndPlaySound32 "chimes.wav", 0
End Sub


You can call that macro from another macro
Application.Run "personal.xls!chimes"

You could for instance call it from an Event macro, which cannot
have your Function in it but you can call a macro that uses the function.
More on Event macros in
http://www.mvps.org/dmcritchie/excel/event.htm

Two event macros examples one for a double-click and one
to chime if not numeric or number is greater than 360.

Install as a worksheet macro by right click on sheet tab
then "View Code" and then insert the following code.

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.Run "personal.xls!chimes"
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 3 Then
On Error GoTo errors
If Target.Value 360 Then GoTo errors
End If
Exit Sub
errors:
On Error GoTo 0
Application.Run "personal.xls!chimes"
End Sub

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"sparky" wrote in message ...
Really appreciate your help, Chip!

...not certain where/how to insert this code, however.
can you spare another moment to tell me ??

Thx again,
JohnC



"Chip Pearson" wrote:

You can play a sound with a VBA call to a Windows API:


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

Sub AAA()
sndPlaySound32 "chimes.wav", 0
End Sub

Change "chimes.wav" to the sound file you want to play.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"sparky" wrote in message
...
Does anyone know if it is possible to have Excel play a sound
clip as a
result of conditional formatting... ? Or maybe as a macro ?

I'm a fairly junior Excel user, so go easy, k ?