Made Sound Alert More Than Once

DaleKeel

Board Regular
Joined
Sep 11, 2019
Messages
56
Office Version
  1. 2013
Platform
  1. Windows
I found this

=IF(U70>=W70,SoundMe(),"")

and it works fine for what I have been doing. Problem is now I need for the sound to alert twice or three times and then stop (after the condition is met). Can anyone help me? Thanks.

For a different situation:
I need an alarm with a different sound than the above sound. Is that possible?

Thanks for your time.
 
Interesting ... I downloaded the workbook again. New instance of your workbook. It runs as expected and YES, there is a second instance running also.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Second instance creates this error :

1590511771493.png


Referencing this FUNCTION :

VBA Code:
Private Function RemoteSoundMe(ByVal RangeAddr As String, ByVal SoundFile As String, ByVal HowManyTimes As Integer, ByVal IntervalDurationInSecs As Single)

    If Len(Dir(SoundFile)) = 0 And UCase(SoundFile) <> "BEEP" Then
        Call StopAllSounds
        Exit Function
    End If
    
    Range(RangeAddr).ID = RangeAddr & "||" & SoundFile & "||" & _
    HowManyTimes & "||" & HowManyTimes & "||" & IntervalDurationInSecs
    
    Call StopAllSounds
    Call SetProp(Application.hwnd, "addressof", VBA.CLngPtr(AddressOf TimerProc))
    Call SetTimer(Application.hwnd, AddAtom(StrPtr(Range(RangeAddr).ID)), 0, AddressOf TimerProc)

End Function
 
Upvote 0
Ahhh .. Good catch !!

ClngPtr won't compile in excel 2007\VBA6 .. I missed that one.

If we replace the problematic line :
Call SetProp(Application.hwnd, "addressof", VBA.CLngPtr(AddressOf TimerProc))
with this :
Call SetProp(Application.hwnd, "addressof", Choose(1, AddressOf TimerProc))
then the code should work accross all versions.

I have updated the workbook example.

Thanks Logit for following this up and for testing.
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top