+ Reply to Thread
Results 1 to 4 of 4

VBA code edit to play wav file - simple answer probably

Hybrid View

ExcelFailure VBA code edit to play wav... 05-08-2013, 05:55 AM
patel45 re: VBA code edit to play wav... 05-08-2013, 01:04 PM
ExcelFailure re: VBA code edit to play wav... 05-09-2013, 02:18 AM
SDruley re: VBA code edit to play wav... 07-13-2013, 11:09 PM
  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Question VBA code edit to play wav file - simple answer probably

    Hi,

    I have the code:

    Private Declare Function sndPlaySound Lib "winmm.dll" _
       Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
    ByVal uFlags As Long) As Long
    
    Private Sub Worksheet_Calculate()
    Static oldval As Variant
    If Range("J2").Value <> oldval Then
        oldval = Range("J2").Value
        PlayWavFile "c:\trimmed.wav", False
    End If
    End Sub
    Sub PlayWavFile(WavFileName As String, Wait As Boolean)
        If Dir(WavFileName) = "" Then Exit Sub ' no file to play
        If Wait Then ' play sound before running any more code
            sndPlaySound WavFileName, 0
        Else ' play sound while code is running
            sndPlaySound WavFileName, 1
       End If
    End Sub
    How can I edit it so that a change in another cell will make another wav file play?

    Thankyou

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    re: VBA code edit to play wav file - simple answer probably

    Private Declare Function sndPlaySound Lib "winmm.dll" _
       Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
    ByVal uFlags As Long) As Long
    
    Private Sub Worksheet_Calculate()
    Static oldval As Variant, oldval1 As Variant
    If Range("J2").Value <> oldval Then
        oldval = Range("J2").Value
        PlayWavFile "c:\trimmed.wav", False
    End If
    If Range("J4").Value <> oldval1 Then
        oldval1 = Range("J4").Value
        PlayWavFile "c:\another.wav", False
    End If
    End Sub
    Sub PlayWavFile(WavFileName As String, Wait As Boolean)
        If Dir(WavFileName) = "" Then Exit Sub ' no file to play
        If Wait Then ' play sound before running any more code
            sndPlaySound WavFileName, 0
        Else ' play sound while code is running
            sndPlaySound WavFileName, 1
       End If
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    re: VBA code edit to play wav file - simple answer probably

    Thanks it works!

  4. #4
    Valued Forum Contributor SDruley's Avatar
    Join Date
    04-27-2009
    Location
    Conover, NC
    MS-Off Ver
    Excel 2010 64 bit
    Posts
    415

    re: VBA code edit to play wav file - simple answer probably

    Patel... good stuff, very helpful
    Turn Data into Information
    Turn Information into Knowledge
    Turn Knowledge into Direction
    Turn Direction into Leadership
    Turn Leadership into Results
    Stephen Druley

    It's not how quickly you think
    But how deeply you think
    The quality of thinking is measured
    by remoteness to conformance
    Stephen Druley

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Error in code - play music file automatically after opening file
    By mukeshbaviskar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-15-2013, 10:06 AM
  2. Trying to embed & play an mp3 file with buttons for play/pause stop & mute
    By jagerman18 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2012, 02:50 AM
  3. Excel 2007 : Code to play wav file.
    By GaidenFocus in forum Excel General
    Replies: 7
    Last Post: 11-13-2010, 02:32 PM
  4. VB code to play a .WAV file
    By fnb10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-09-2010, 08:26 PM
  5. Simple Edit for Multiple File Reference?
    By perfectview in forum Excel General
    Replies: 1
    Last Post: 06-03-2009, 10:57 PM

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