#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Alarm 2

Excel 2010

I have an earlier post related to this one. I am trying to set-up an audible alarm when a cell has a value greater than 0.

I was using this VBA for my alarm function:

'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_SYNC Or SND_FILENAME)
Alarm = True
Exit Function
End If
ErrHandler:
Alarm = False
End Function

It worked at one time but now I get #NAME? in the cell that I use the function.

Can you help me troubleshoot this error ?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Alarm 2

I think it may have to do with one of two things:

1. On the line starting "Call PlaySound...", the Const is missing an "A" ("SND_SYNC" vs "SND_ASYNC").

2. If that doesn't solve it, you may check that the Alarm function is located in a Module other than one of the Sheet modules or the ThisWorkbook module. When I pasted the code to the ThisWorkbook module, I also received a #NAME? error, but pasting it to Module1 worked fine.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Alarm 2

On Monday, November 5, 2012 2:09:08 PM UTC-5, Ben McClave wrote:
I think it may have to do with one of two things:



1. On the line starting "Call PlaySound...", the Const is missing an "A" ("SND_SYNC" vs "SND_ASYNC").



2. If that doesn't solve it, you may check that the Alarm function is located in a Module other than one of the Sheet modules or the ThisWorkbook module. When I pasted the code to the ThisWorkbook module, I also received a #NAME? error, but pasting it to Module1 worked fine.


Thanks. I tried both suggestions and still get #Name?

I found another code that I am trying to get to work:


Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVallpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long


Public Function PlayWavFileIF(WavFile As String, Condition As Boolean) As Boolean
Const SND_ASYNC = &H1, SND_FILENAME = &H20000
If Condition Then PlaySound WavFile, 0, SND_ASYNC Or SND_FILENAME
PlayWavFileIF = Condition
End Function

In A1 I have this formula =PlayWavFileIF("C:\Users\Administrator\Desktop\sou nd1.wav", B1=1).

I can get the formaula to change from False to True.

However, when it is True, I can get the sound1.wav to play.

Any thoughts on this ?
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
Alarm Tomas Excel Worksheet Functions 3 November 24th 09 12:15 AM
How to set an alarm in excel... Fuzzy Excel Discussion (Misc queries) 1 February 12th 09 07:39 AM
Recalc Alarm Mike H. Excel Programming 4 August 9th 07 10:31 PM
Alarm Timer Philosophaie Excel Programming 3 July 12th 07 11:57 PM
Alarm Manthony Excel Programming 0 June 6th 06 03:46 PM


All times are GMT +1. The time now is 03:47 PM.

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

About Us

"It's about Microsoft Excel"