+ Reply to Thread
Results 1 to 2 of 2

Play random sound file every x seconds, or when cursor is in particular cell

  1. #1
    Registered User
    Join Date
    01-20-2014
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    59

    Play random sound file every x seconds, or when cursor is in particular cell

    Is there vba I can use to play a random sound file either after every x seconds or if the cursor happens to reach a specific cell?

    I'm able to play sound files, and think I could work out how to do it if the cursor reached a specific cell, but wouldn't know how to play a random sound file.

    For example, by way of explaining a random sound file, I have a list of around 8-10 short sound clips, that don't need to be played in any specific order. Just when a condition is met, then it selects one of the sound files randomly and plays it.

    Is that possible?

    Any advice would be greatly appreciated

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2012
    Location
    Melbourne, VIC
    MS-Off Ver
    Excel 2016
    Posts
    750

    Lightbulb Re: Play random sound file every x seconds, or when cursor is in particular cell

    Try this:
    To play a random sound:
    • In your Sound() macro, Define a String array, like sFilePath(1 to 10) and store the full file path with names & extension for the 10 short sound clips you have.
    • Now generate a random number between 1 and 10 use RND Function
    • E.g. Int ((10 - 1 + 1) * Rnd + 1) would return a random number between 1 and 10
    • Store this Random Number to an integer variable, say iInt
    • and now you may call the specific array element, like sFilePath(iInt) to play a random sound

    Now for the 2nd part (playing it after every X Seconds or on Cursor reaching a cell
    • For cursor reaching a cell, call the Sound Macro from the Worksheet_SelectionChange event when the Target intersects with the desired cell
    • For playing every "x" seconds (say 30 seconds), at the end of your Sound Macro, call another Macro, say Repeat() (see code below)
    • Now repeat will call Sound() after 30 seconds; and the Sound() will call repeat again after playing the sound, going into a sort of infinite loop.
    I saw the brilliant idea here
    Please Login or Register  to view this content.
    I'd be happy to hear the outcome.

    Cheers!
    Jewel
    Last edited by jewelsharma; 04-15-2014 at 12:53 AM. Reason: forgot to mention where I saw the original solution.

+ 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. Display Picture & Play Sound for 5 seconds
    By sisterwolf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2010, 01:58 PM
  2. Play sound file at set time each day
    By thetaplus in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-23-2008, 01:03 AM
  3. excel to play sound file
    By svanni in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-03-2006, 11:47 PM
  4. Display Text and Play Sound file
    By Soniya in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-27-2006, 02:20 AM
  5. [SOLVED] Play Sound File
    By Soniya in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-22-2006, 06:50 AM

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