+ Reply to Thread
Results 1 to 10 of 10

Play Wav File and do other stuff while playing

Hybrid View

  1. #1
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Play Wav File and do other stuff while playing

    Hi,

    I have this small script below which plays a wav file which works fine. However the script stops until the wav file is completed.

    How can I make the Script continue on instead of waiting?

    Also:
    Is it possible for the wav file to keep playing over and over again till the user clicks the commandbutton1 or the commandbutton1 is not visible?

    Thank You for the help, Mike

    Sub NewOpen2()
    Range("A1").Select
    ActiveWindow.Zoom = True
    Range("A8").Value = ""
    PLAYWAV3
    Range("A8").Value = "Click The Start Button To Begin"
    Application.Wait (Now + TimeValue("0:00:2"))
    CommandButton1.Visible = True
    End Sub
    Last edited by realniceguy5000; 10-27-2011 at 12:59 PM.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Play Wav File and do other stuff while playing

    Post the PlayWav3 routine.

    For an embedded file playing from a userform:
    Private tNow As Date
    
    Private Sub CommandButton1_Click()
      tNow = 0
      Unload Me
    End Sub
    
    Private Sub UserForm_Activate()
      tNow = Now + TimeValue("00:01:10")
      Do Until tNow < Now
        DoEvents
        Worksheets("Boo").OLEObjects("Object 1").Verb 'Set object name as needed.
        Loop
    End Sub
    An API method: http://www.vbaexpress.com/forum/showthread.php?t=37056
    Last edited by Kenneth Hobson; 10-26-2011 at 12:11 PM.

  3. #3
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Play Wav File and do other stuff while playing

    Sorry for the delay I way in a meeting. Here is the routine you requested,

    Thanks for looking...

    Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszName As String, ByVal dwFlags As Long) As Long
    'Put in Standard module, only, like: Module1!
    Const SND_SYNC = &H0
    Const SND_ASYNC = &H1
    Const SND_FILENAME = &H20000
     
    Sub PLAYWAV3()
    Dim wavefile, x
    wavefile = "wmpaud7.wav"
    Call PlaySound(wavefile, SND_ASYNC Or SND_FILENAME)
    End Sub

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Play Wav File and do other stuff while playing

    Hello realniceguy2000,

    You need to add in the SND_LOOP constant.
    Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszName As String, ByVal dwFlags As Long) As Long
    'Put in Standard module, only, like: Module1!
    Const SND_SYNC = &H0
    Const SND_ASYNC = &H1
    Const SND_LOOP = &H8
    Const SND_FILENAME = &H20000
     
    Sub PLAYWAV3()
    Dim wavefile, x
    wavefile = "wmpaud7.wav"
    Call PlaySound(wavefile, SND_ASYNC Or SND_LOOP Or SND_FILENAME)
    End Sub

    To stop the sound use this macro.
    Sub StopSound()
        Call PlaySound("", 0, 0)
    End Sub
    Last edited by Leith Ross; 10-26-2011 at 01:31 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Play Wav File and do other stuff while playing

    Thank You,

    But how cant I make the script keep running. When I run or step through the script the wav file starts playing and the script stops till the wav file completes then the script starts up again.

    For Example: Once the script goes to the playwav3 script it will not return tll the wav completes playing.

    What I would like is the wav to keep playing while the rest of the script runs then the wav can stop once the button is clicked.

    This code below is is all in a sheet mod that is triggered when the workbook is opened. In a reg mod 1 is where I have the Declare Function part of the script.

    Any other idea's

    Thanks Mike

    Sub NewOpen2()
    Range("A1").Select
    ActiveWindow.Zoom = True
    Range("A8").Value = ""
    PLAYWAV3   
    Range("A8").Value = "Click The Start Button To Begin"
    Application.Wait (Now + TimeValue("0:00:1"))
    CommandButton1.Visible = True
    End Sub
    Sub PLAYWAV3()
    Dim wavefile, x
    wavefile = "C:\Documents and Settings\MAlston\Desktop\New Audit\Audit Log Test 10-21-11\Audit Lot Checks\wmpaud7.wav"
    Call PlaySound(wavefile, SND_ASYNC Or SND_LOOP Or SND_FILENAME)
    End Sub

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Play Wav File and do other stuff while playing

    Hello Mike,

    I will have to play with this. The SND_ASYNC should return back to the calling macro after the sound file has been started. The file should continue to play until you run the macro to stop it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1