Home |
Search |
Today's Posts |
#1
|
|||
|
|||
can I use IF statement to call a VBA function ?
I have used the code in here to create a function called Alarm
http://spreadsheetpage.com/index.php...a_cells_value/ I can get it to play a sound by using =alarm(a1,"2") to test whether a1 is 2 Can I use an IF statement to trigger the function alarm ? Thanks ! Last edited by acwai : April 13th 12 at 04:06 AM |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
can I use IF statement to call a VBA function ?
Yes, but I wonder why you would want that when the function has an IF statement within already.
|
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
can I use IF statement to call a VBA function ?
"acwai" wrote:
I have used the code in here to create a function called Alarm http://tinyurl.com/c59tec9 I can get it to play a sound by using =alarm(a1,"2") to test whether a1 is 2 What a silly thing to do! Not you; the design of the function. "acwai" wrote: Can I use an IF statement to trigger the function alarm ? Redesign function Alarm as follows: '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(Optional retnval = "") Dim WAVFile As String Const SND_ASYNC = &H1 Const SND_FILENAME = &H20000 On Error GoTo ErrHandler WAVFile = ThisWorkbook.Path & "\sound.wav" 'Edit this statement Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME) ErrHandler: Alarm = retnval End Function Then you can call it with the following equivalent IF expression: =IF(A12,Alarm(),"") And of course, this permits you to use Alarm with much more complicated conditional expressions, for example: =IF(AND(A12,B1<3,C1=4),Alarm(),"") By default, Alarm returns the null string (""). The optional parameter allows you to use Alarm in arithmetic expressions, to wit: =IF(A12,2+Alarm(0),"") or more simply: =IF(A12,Alarm(2),"") |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Call Statement | Excel Programming | |||
Using the Call Statement | Excel Programming | |||
Variable in call statement | Excel Programming | |||
Call Statement and Return Value | Excel Programming | |||
Can you call a macro as in an IF statement | Excel Programming |