adding sound to an excel i.e. warning if data is negative

G

Gary''s Student

Enter this macro in worksheet code:


Sub Worksheet_Change(ByVal Target As Excel.Range)
' gsnu
If Intersect(Range("A1:A10"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value < 0 Then
s = "warning negative value"
Application.Speech.Speak s
End If
Application.EnableEvents = True
End Sub


The routine checks entries in A1 thru A10. If the entries are negative, a
warning is issued.


Just be sure to put the code in worksheet code, not a module.
 
D

David

=?Utf-8?B?R2FyeScncyBTdHVkZW50?= wrote
Enter this macro in worksheet code:


Sub Worksheet_Change(ByVal Target As Excel.Range)
' gsnu
If Intersect(Range("A1:A10"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
If Target.Value < 0 Then
s = "warning negative value"
Application.Speech.Speak s
End If
Application.EnableEvents = True
End Sub


The routine checks entries in A1 thru A10. If the entries are
negative, a warning is issued.


Just be sure to put the code in worksheet code, not a module.

I couldn't get it to work in XL2000 (error 438), but some searching allowed
me to adapt:

Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim s As Object
Set s = CreateObject("SAPI.SpVoice")
If Intersect(Range("A1:A10"), Target) Is Nothing Then GoTo ws_exit
Application.EnableEvents = False
If Target.Value < 0 Then
s.Speak "warning,, negative value" 'dbl commas introduce a pause
End If
ws_exit:
Set s = Nothing
Application.EnableEvents = True
End Sub
 
Top