View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
___Zoom[_2_] ___Zoom[_2_] is offline
external usenet poster
 
Posts: 11
Default Excel sound alert problem

Rob,
Thanks for your suggestions. Since I have P.M sessions as well for "start
lesson" alerts (lessons 8, 9, and 10), I am using cells J1 and K1 for
controlling the criteria displayed in cells D3 and D4. Now there is a "dong"
sound (default windows alert sound) when the criteria is met. All seems to
be working OK, apart from not playing the desired *.wav file. My wav file
resides in "D:\Sitem_Excel\sound.wav" and together with D1 and E1, that is
all that I have changed from your suggestion codes. I have placed the Code
into the Module1 and Workbook code pages as well with no difference. I am
not getting any error messages while the macro is running or when the
criteria is met and "dong" sounds. Hope you may find the reason...
Sincerely

"Rob van Gelder" wrote in message
...
Zoom,

I've taken a quick look into your problem.

Here's what I can suggest:
(You may want to change E1 to match)

D1 =
=IF(AND(A1=7,B1=55),"start lesson 1",IF(AND(A1=8,B1=35),"start lesson
2",IF(AND(A1=9,B1=15),"start lesson 3",IF(AND(A1=10,B1=10),"start lesson
4",IF(AND(A1=10,B1=50),"start lesson 5",IF(AND(A1=11,B1=40),"start lesson
6",IF(AND(A1=12,B1=20),"start lesson 7","--")))))))

E1 =
=IF(D1<"--",PlayWavFile("C:\T\Chimes.wav"),"")

Code Module:

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA"

(ByVal
lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Public Function PlayWavFile(WavFile As String) As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
PlaySound "C:\T\chimes.wav", 0, SND_ASYNC Or SND_FILENAME
PlayWavFile = ""
End Function

Public Sub zaman()
Sheets("Sheet1").Range("A1").Value = Hour(Now())
Sheets("Sheet1").Range("B1").Value = Minute(Now())
Sheets("Sheet1").Range("C1").Value = Second(Now())
Nextzaman
End Sub

Private Sub Nextzaman()
Application.OnTime Now + TimeValue("00:00:05"), "zaman"
End Sub


Rob



"___Zoom" wrote in message
...
Here are my answers for your questions;

a) Here is the code to check the system time:
------------------------
Sub zaman()
Sheets("Sheet1").Range("A1").Value = Hour(Now())
Sheets("Sheet1").Range("B1").Value = Minute(Now())
Sheets("Sheet1").Range("C1").Value = Second(Now())
Nextzaman
End Sub
-------------------------
and here is the code that re-runs the macro at minute intervals:
---------------------------------
Private Sub Nextzaman()
Application.OnTime Now + TimeValue("00:01:00"), "zaman"
End Sub
---------------------------------

b) For Alarm code invoking I tried to do it like this:

'Windows API function declaration
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Function Alarm(Cell, Condition)
Dim WAVFile As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
On Error GoTo ErrHandler

' If Evaluate(Cell.Value & Condition) Then - I removed this line

from
the original code because I thought that I could do the same control

with
the long IF...statement below. I also was not sure if the
"IfEvaluate(Cell.Value & Condition) Then" format will work for two cells

(A1
& B1). Couse the original statement format looks like it only accepts "a
numerical cell value" not more...

WAVFile = "D:\Myfolder" & "\sound.wav" ' Original location of my
alarm sound file

If (Sheet1!A1 = 7 And Sheet1!B1 = 55) Or (Sheet1!A1 = 8 And
Sheet1!B1 = 35) Or (Sheet1A1 = 9 And Sheet1!B1 = 15) Or (Sheet1!A1 = 9

And
Sheet1!B1 = 55) Or (Sheet1!A1 = 10 And Sheet1!B1 = 10) Or (Sheet1!A1 =

10
And Sheet1!B1 = 50) Or (Sheet1!A1 = 11 And Sheet1!B1 = 30) Or (Sheet1!A1

=
11 And Sheet1!B1 = 40) Or (Sheet1!A1 = 12 And Sheet1!B1 = 20) And

(Sheet1!A1
= 13 And Sheet1!B1 = 0) Then Call PlaySound(WAVFile, 0&, SND_ASYNC Or
SND_FILENAME)

' The long statement above tries to call the alarm sound function

depending
upon the conditions
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function
---------------------------------------------
Private Sub Workbook_Open()
Application.Run "zaman"
Call Alarm ' I am not sure if there needs to be such an additonal line

like
this here. Without this line the "zaman" module works OK.
End Sub
---------------------------------------------

Hope you have a clearer view now for my problem...

Do you think I should have added the "Call Alarm" command into the

"Private
Sub Nextzaman()" module rather then "Private Sub Workbook_Open()" ?

Thanks for not giving up on me. I'll be waiting impatiantly for your
solution suggestions :)
TIA

"Bob Phillips" wrote in message
...
Nearly given up on you<vbg.

Two questions,

How is the hour and minutes in A1 and B1 being updated, as it seems to

me
that the formula will only work if those cells re-calculate at the

correct
moment.

How do you think the alarm code is invoked, that is what in your

formula
is
forcing it, as I can't see it in your response.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"___Zoom" wrote in message
...
Bob,
Thanks for your reply. Here is my problem with some detail:
I am displaying my system clocks hour on Sheet1 A1 and minute on

Sheet1
B1.
Using these figures with some criteria I have created IF..

statements
to
display certain messages for some cells. An example is:

=IF(AND(A1=7;B1=55);"start lesson 1";IF(AND(A1=8;B1=35);"start

lesson
2";IF(AND(A1=9;B1=15);"start lesson 3";IF(AND(A1=10;B1=10);"start

lesson
4";IF(AND(A1=10;B1=50);"start lesson 5";IF(AND(A1=11;B1=40);"start

lesson
6";IF(AND(A1=12;B1=20);"start lesson 7";"--")))))))

All works fine. But I wanted to add sound alerts for the same

criteria
too.
I've tried the macro examples given as references to previous work

(with
alterations to suit my case of course):
================================================== ==
'Windows API function declaration
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long


Function Alarm(Cell, Condition)
Dim WAVFile As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
On Error GoTo ErrHandler
If Evaluate(Cell.Value & Condition) Then
WAVFile = ThisWorkbook.Path & "\sound.wav" 'Edit this

statement
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function
===========================================
AND
===========================================
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Sub PlayWAV()
WAVFile = "dogbark.wav"
WAVFile = ThisWorkbook.Path & "\" & WAVFile
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub
====================================
but failed to make it work. Don't know what I am doing wrong. I'd
appreciate
if anyone could help.
Zoom


"Bob Phillips" wrote in message
...
Zoom,

I just created this simple worksheet change event code and it

worked
okay

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address(False, False) = "A1" Then
Alarm Target, "100"
End If

End Sub

I copied John's Alarm Fun ction into a normal code module, this

code
in
the
sheet module, and change the sound file as suggested by John.

What are you doing?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)