PDA

View Full Version : add a condition



maninjapan
05-02-2011, 01:55 AM
I am using the current code as an alert for real time P&L on my trading account. If it exceeds a certain limit it triggers a sound and email alert.
However I would like to add the option of turning off the sound alert. How can I add an extra condition to just the sound alert part without affecting the email alert section?

Thanks in advance


Private Sub Worksheet_Calculate()
Dim tf As Boolean, soundFile As String
Dim myVal As Double

If IsError(Range("B4")) Then
myVal = 0
Else
myVal = Range("B4").Value
End If



If myVal <= Range("G3").Value And Range("H3").Value <> "Limit" Then
Application.EnableEvents = False
Range("H3").Value = "Limit"
Application.EnableEvents = True
soundFile = "C:\tt\sounds\alarm2.wav"
Call sndPlaySound32(soundFile, SND_LOOP Or SND_ASYNC)
Call CDO_Mail_Small_Text_2


If MsgBox("Level I !!", vbOKOnly Or vbQuestion) = vbOK Then
Call sndPlaySound32(0&, 1&)
End If
End If

End Sub

Bob Phillips
05-02-2011, 02:03 AM
Private Sub Worksheet_Calculate()
Dim tf As Boolean, soundFile As String
Dim myVal As Double

If IsError(Range("B4")) Then
myVal = 0
Else
myVal = Range("B4").Value
End If



If myVal <= Range("G3").Value And Range("H3").Value <> "Limit" Then
Application.EnableEvents = False
Range("H3").Value = "Limit"
Application.EnableEvents = True
soundFile = "C:\tt\sounds\alarm2.wav"
If Me.Range("H1").Value = "No" Then 'change to suit <<<<<<<<<<<<<<<<<

Call sndPlaySound32(soundFile, SND_LOOP Or SND_ASYNC)
End If

Call CDO_Mail_Small_Text_2


If MsgBox("Level I !!", vbOKOnly Or vbQuestion) = vbOK Then
Call sndPlaySound32(0&, 1&)
End If
End If
End Sub