Consulting

Results 1 to 19 of 19

Thread: System beep

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    System beep

    After my code is done I want it to run a system beep. How can I do this?

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    The VBA comand for making the beep sound is

    Beep

    It will sound just one beep so if you want more you need to repeat the line of code or put it in a loop.

  3. #3
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    I put beep in but it doesn't make a sound? And I don't have it on mute and I can hear other sounds.

    Daniel

  4. #4
    VBAX Contributor compariniaa's Avatar
    Joined
    Jun 2006
    Location
    Santa Clarita, CA
    Posts
    117
    Location
    Quote Originally Posted by Djblois
    I put beep in but it doesn't make a sound? And I don't have it on mute and I can hear other sounds.

    Daniel
    I think system admins can turn sounds off for computers, which may affect whether or not you can hear the beep. I can hear sounds on my PC, evidenced by this macro:

    [vba] sub Sound()
    If Application.CanPlaySounds = False Then
    MsgBox "Your computer cannot play sounds"
    Else
    MsgBox "Your computer can play sounds"
    End If[/vba] hope this helps
    Last edited by compariniaa; 07-17-2006 at 03:33 PM.

  5. #5
    Yes, that is not to be forgotten. I recently was trying to use an API to play a WAV sound, and it kept failing. I added:
    Application.EnableSound = True
    and ...Voila!.. it worked!

  6. #6
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Daniel, it works for me, although it is very difficult to get it to beep more than once.
    You may need to turn the sound up higher to hear it.

  7. #7
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by OBP
    Daniel, it works for me, although it is very difficult to get it to beep more than once.
    [VBA]Sub test()
    Beep
    Application.Wait Now + TimeValue("00:00:01")
    Beep
    End Sub[/VBA]
    And the sound works for me...

    Windows XP
    Excel 2003




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  8. #8
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    lol I have the sound up all the way right now. lol

  9. #9
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    I just tried this code on another computer and it didn't work either? have any idea why?

  10. #10
    I tried to get Beep to work on 3 different computers, and I never heard anything. What I really need is a sound that goes "phffft!".

  11. #11
    I just thought of something. Maybe you can get the speech facility to help you. Look into it ... it's really kinda cool.

  12. #12
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Since, the system beep won't work can someone help me to get it to make any sound? I just want it to make a noise when it is done.

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    How about using a .wav file?
    [VBA]
    Option Explicit
    'API Class to take care of playing the file
    Public Declare Function sndPlaySound32 Lib "winmm.dll" _
    Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
    ByVal uFlags As Long) As Long
    Sub VBASound()
    'Call Api to play LoadIt.wav witch is in the same folder as
    'the active document!
    Call sndPlaySound32(ActiveWorkbook.Path & "\LoadIt.WAV", 0)
    End Sub
    [/VBA]
    I think this is a kb entry from some time ago.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  14. #14
    Or you can put the following statement at the end of your code:
    [VBA]Application.Speech.Speak("Beep")[/VBA]

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    For sound see here
    http://www.vbaexpress.com/forum/showthread.php?t=8736

    Hi Steve,
    DRJ did the Sound KB
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    I have just had a thought, the guys that can't get the sound to work, what References have you got ticked in the reference library?

  17. #17
    What reference should I have that I might not have??

    P.S. I can use the text to speech feature OK.

  18. #18
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    I have the following ticked
    Visual Basic For Applications - (Which I assume you must have)
    Microsoft Excel 10.0 Object Library
    OLE Automation
    Microsoft Office 10.0 Object Library

  19. #19
    VBAX Newbie
    Joined
    Jun 2006
    Location
    Oregon
    Posts
    3
    Location
    Also for Beep, you need to make sure that you have a sound assigned for Default Beep in the Sounds & Multimedia (this is what it's called in Windows 2000, not sure about XP) Control Panel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •