Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Aug 2004
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code that gives sound (office XP)

    hi, i already have a complete code that runs fine. the code takes about 30min to complete. and i was thinking if there is a code that gives sound to insert to the end of my code so it gives sound after the code completes. is such code appears, please?

    p/s. the louder the sound better. (and maybe the longer the sound better?) so i can hear it from next room.
    Edit: i just got this from Help menu. "Application.EnableSound = True" and my system running so cannot try the momment. if there is another way, please let me know.

    Thanks.

  2. #2
    2 Star Lounger
    Join Date
    Aug 2004
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code that gives sound (office XP)

    hi, i don't know about vba code and i got the code from macro recording. about this enablesound property i believe there must be more to insert than the string in the bottom code. what's the beginning code, if that to makes it happen? there are sound when i save file, is there a sound similar?

    Thanks again for your kind help.

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: code that gives sound (office XP)

    The simplest code is

    Beep

    the volume will depend on your volume settings both in the Control Panel and on any physical volume control on your speakers.

    To play the WAV file of your choice via VBA in an Office App, see if this works:

    ' the declaration must be at the start of your module
    Public Declare Function sndPlaySound Lib "winmm.dll" _
    Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
    ByVal uFlags As Long) As Long

    Sub PlayWavFile()
    sndPlaySound "c:documents and settingsmy musicmywav.wav", 1
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    2 Star Lounger
    Join Date
    Aug 2004
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code that gives sound (office XP)

    hi. thanks for reply. i found no 'Beep' in Windows XP Home and yes to Windows XP Professional cause i use beep statement example in help file. [img]/forums/images/smilies/smile.gif[/img]. i just change sound to 'Default Beep' event in sound control in Control Panel to my choice from selection there. i don't know how to use your method of the code you provided, so i use the beep. and i make no sounds to others events except Default Beep so i just have sound after complete my system and others remain the same. now for Windows Home (i use it for notebook) this e.g. not work either when i disable the sound option of Office Assistant:
    Sub Macro1()
    With Assistant
    .Visible = True
    .On = True
    If Not Sounds Then Sounds = True
    .Animation = msoAnimationGreeting
    End With
    End Sub

    what other ways to get sound after code and other program events has no sounds??

    Thanks.

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: code that gives sound (office XP)

    Beep is a VBA Statement found at least in Outlook, Word and Excel, if not in all the Office products. Your original post states that you are working in VBA; which specific Application are you working in? Whether you are working with XP Home or XP Pro has nothing to do with the Beep Statement. If you are working in a Microsoft Application, make sure that your PC sounds are turned on, and up, and then run this code:

    Sub BeepMe()
    Beep
    End Sub

    What happens?

    The code you posted is for Sounds coming from the Office (Animated Help) Assistant. That's a very indirect way to get sounds if you are coding VBA in an Application, and you would first have to instance the Office Assistant, which I don't know that you have done because you haven't posted any other code.
    -John ... I float in liquid gardens
    UTC -7ąDS

  6. #6
    2 Star Lounger
    Join Date
    Aug 2004
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code that gives sound (office XP)

    hi John. thanks for your reply again. i use beep for Excel. i used

    Sub macro1()
    Dim I
    For I = 1 To 3 ' Loop 3 times.
    Beep ' Sound a tone.
    Next I
    End Sub

    from the help file. i tried the above code and the code you just provided in a pc and a notebook. the pc works perfect. the notebook no sound. so the notebook i tried the indirect way from the help file also with condition the sound enable in office assistant (i don't want that). the difference of two computers are a pc v notebook and xp professional and xp home. i haven't check the office what version in notebook cause system still running. in control panel over the sound and audio devices, there is 'Default Beep' in 'Program Event' in 'Sounds' tab in pc but not in notebook.

    so, what then could be wrong.

    maybe use other sound than beep in notebook?? what is the code, i don't know. still searching...

  7. #7
    2 Star Lounger
    Join Date
    Aug 2004
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code that gives sound (office XP)

    hi. now i got this example and a small 'tick' sound heard in notebook:

    Example: Playing a WAV File
    The example below contains the API function declaration, plus a simple subroutine to play a sound file called dogbark.wav, which is assumed to be in the same directory as the workbook.

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

    Const SND_SYNC = &H0
    Const SND_ASYNC = &H1
    Const SND_FILENAME = &H20000

    Sub PlayWAV()
    WAVFile = "dogbark.wav"
    WAVFile = ThisWorkbook.Path & "" & WAVFile
    Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
    End Sub
    In the example above, the WAV file is played asynchronously. This means execution continues while the sound is playing. If you would like code execution to stop while the sound is playing, use this statement:

    Call PlaySound(WAVFile, 0&, SND_SYNC Or SND_FILENAME)

    i got it from this link: http://j-walk.com/ss/excel/tips/tip59.htm

    maybe i can try this one to be better. it is about the wav file. where do i get wav file and how to get it in here?

    Thanks.

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: code that gives sound (office XP)

    > where do i get wav file and how to get it in here?

    Microsoft supplies some WAV files (such as the various Windows sounds). If you use the Windows recorder, I believe it will make a WAV file, so then you can create any sound you like, assuming you have a microphone.

  9. #9
    2 Star Lounger
    Join Date
    Aug 2004
    Posts
    103
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code that gives sound (office XP)

    hi Jscher2000, hi John, finally at least i got the sound i think i wanted to alert me after i go somewhere dreaming. Thanks.

Posting Permissions

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