• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

The Beep

Eloise T

Active Member
I want to add "Beep" at the end of a macro so that I hear 3 distinct beeps so I know it's done.

If I put:

Beep
Beep
Beep

I only hear 1 Beep because the 3 Beeps happen so quickly. What can I add to the code to slow down the beeping so I hear 3 distinct beeps?
 
Ah. I use an email for that. Just at the end of a long routine I throw on a quick email that says "your stuff is done". It also works for any constituent users you may have who insist being notified of it too.
 
Ah. I use an email for that. Just at the end of a long routine I throw on a quick email that says "your stuff is done". It also works for any constituent users you may have who insist being notified of it too.
Please reply with the code that does that. It's probably a bit more than I need at the moment, but it may come in handy in the future.
 
Please reply with the code that does that. It's probably a bit more than I need at the moment, but it may come in handy in the future.

Code:
Sub EmailNote()
   
  Dim sDistroList As String
   
   
  Set OutApp = CreateObject("Outlook.Application")
  Set OutMail = OutApp.CreateItem(0)
   
  sDistroList = whoever@whereever.com
   
  With OutMail
  .SentOnBehalfOfName = ""
  .To = sDistroList
  .bcc = ""
  .cc = ""
  .Subject = "Project Updated"
   
  .body = "Project UPdated"


  .display
  .send

  End With
  Set OutMail = Nothing
  Set OutApp = Nothing
   


End Sub


This is pretty generic code to do it. In practice, I have this built up in a class so at various points I can have something like

dim cUpdateMessage as new cEmailNotification

cUpdateMessage.quicksend "email@address.com", "project updated" just to be quick.
 
Hi !

Sometimes I play music or voice from mp3 or wav file
but for this kind of alert I use some musical beep :​
Code:
Private Declare Function kBeep Lib "kernel32" Alias "Beep" (ByVal Frq&, ByVal Dur&) As Boolean

Sub kBeepDemo()
    FD = [{392,494,588,740,880,740,880;200,100,200,100,400,100,900}]
    For L& = 1 To UBound(FD, 2):  kBeep FD(1, L), FD(2, L):  Next
End Sub
Do you like it ? So thanks to click on bottom right Like !
 
Hi !

Sometimes I play music or voice from mp3 or wav file
but for this kind of alert I use some musical beep :​
Code:
Private Declare Function kBeep Lib "kernel32" Alias "Beep" (ByVal Frq&, ByVal Dur&) As Boolean

Sub kBeepDemo()
    FD = [{392,494,588,740,880,740,880;200,100,200,100,400,100,900}]
    For L& = 1 To UBound(FD, 2):  kBeep FD(1, L), FD(2, L):  Next
End Sub
Do you like it ? So thanks to click on bottom right Like

I received the following error:
upload_2017-7-24_21-54-59.png
 
Try replace the declaration line with this
Code:
#If VBA7 Then
    Private Declare PtrSafe Function kBeep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
#Else
    Private Declare Function kBeep Lib "kernel32" (ByVal Frq&, ByVal Dur&) As Boolean
#End If
 
Try replace the declaration line with this
Code:
#If VBA7 Then
    Private Declare PtrSafe Function kBeep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
#Else
    Private Declare Function kBeep Lib "kernel32" (ByVal Frq&, ByVal Dur&) As Boolean
#End If
upload_2017-7-25_12-13-36.png

I must have not put it in the correct place?
 
These lines are put in declaration part at the very top of the standard module
Code:
Option Explicit

#If VBA7 Then
    Private Declare PtrSafe Function kBeep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
#Else
    Private Declare Function kBeep Lib "kernel32" (ByVal Frq&, ByVal Dur&) As Boolean
#End If

Sub kBeepDemo()
    FD = [{392,494,588,740,880,740,880;200,100,200,100,400,100,900}]
    For L& = 1 To UBound(FD, 2):  kBeep FD(1, L), FD(2, L):  Next
End Sub
 
Psst. Above will give error, since none of the variables are declared ;)

Below worked on my 64-bit Excel.
Code:
Option Explicit
#If VBA7 Then
    Private Declare PtrSafe Function kBeep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Boolean
#Else
    Private Declare Function kBeep Lib "kernel32" (ByVal Frq&, ByVal Dur&) As Boolean
#End If

Sub kBeepDemo()
Dim FD, L As Long
    FD = [{392,494,588,740,880,740,880;200,100,200,100,400,100,900}]
    For L& = 1 To UBound(FD, 2)
        kBeep FD(1, L), FD(2, L)
    Next
End Sub
 
Thanks a lot Mr. Chihro for this remark .. In fact I put this Option Explicit because it appears at the very top of the module and I needed to show Eloise that the code will be put below that statement "Option Explicit" .. but you are right as variables are not declared .. Thanks a lot
 
I forgot to mention, without 'Alias "Beep"' portion, code gave me error "can't find DLL entry point kBeep in kernel32".
 
Replace kBeep with Beep in the code
Code:
Option Explicit
#If VBA7 Then
    Private Declare PtrSafe Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Boolean
#Else
    Private Declare Function Beep Lib "kernel32" (ByVal Frq&, ByVal Dur&) As Boolean
#End If

Sub kBeepDemo()
Dim FD, L As Long
    FD = [{392,494,588,740,880,740,880;200,100,200,100,400,100,900}]
    For L& = 1 To UBound(FD, 2)
        Beep FD(1, L), FD(2, L)
    Next
End Sub
 
Replace kBeep with Beep in the code
Code:
Option Explicit
#If VBA7 Then
    Private Declare PtrSafe Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Boolean
#Else
    Private Declare Function Beep Lib "kernel32" (ByVal Frq&, ByVal Dur&) As Boolean
#End If

Sub kBeepDemo()
Dim FD, L As Long
    FD = [{392,494,588,740,880,740,880;200,100,200,100,400,100,900}]
    For L& = 1 To UBound(FD, 2)
        Beep FD(1, L), FD(2, L)
    Next
End Sub
upload_2017-7-25_16-12-27.png
 
Back
Top