Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Excel sound alert problem

I am having difficulties on implementing Excel sound alert function to
an XL application of mine. In my problem, I want to trigger the sound file
depending on the content of two cells (Sheet1's A1 and B1: which should have
10 suitable pairs for triggering). Furthermore, I want to bound the process
of checking these cells content to a automatic check of system time of my
PC. The system clocked should be checked every munite and if the conditions
are met for Sheet1 A1 and Sheet1 B1 then the sound file be played. Can
anyone help me with this please?
I can get into more detail if any group member is interested...TIA



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel sound alert problem

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)

"___Zoom" wrote in message
...
I am having difficulties on implementing Excel sound alert function to
an XL application of mine. In my problem, I want to trigger the sound file
depending on the content of two cells (Sheet1's A1 and B1: which should

have
10 suitable pairs for triggering). Furthermore, I want to bound the

process
of checking these cells content to a automatic check of system time of my
PC. The system clocked should be checked every munite and if the

conditions
are met for Sheet1 A1 and Sheet1 B1 then the sound file be played. Can
anyone help me with this please?
I can get into more detail if any group member is interested...TIA





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Excel sound alert problem

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)




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel sound alert problem

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)






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Excel sound alert problem

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)












  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Excel sound alert problem

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)











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
How do I create a sound alert in excel spreadsheet shaun t Excel Discussion (Misc queries) 8 November 23rd 08 12:09 AM
sound alert from excel dan Excel Discussion (Misc queries) 0 June 26th 06 03:49 AM
Sound alert Antonio Excel Discussion (Misc queries) 3 May 30th 06 07:09 PM
Excel sound alert Michelle Excel Programming 5 January 3rd 04 10:55 AM
How can I make a sound alert using macro in Excel! (But not use speaker) bookworm98 Excel Programming 5 December 11th 03 08:49 AM


All times are GMT +1. The time now is 09:01 AM.

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

About Us

"It's about Microsoft Excel"