+ Reply to Thread
Results 1 to 10 of 10

Need to play a wav file based on path and filename in a selected cell using macro: SOLVED!

  1. #1
    Registered User
    Join Date
    03-30-2016
    Location
    nowhere
    MS-Off Ver
    2014
    Posts
    7

    Need to play a wav file based on path and filename in a selected cell using macro: SOLVED!

    I've been trying to figure this out on my own, and I'm stuck. Just can't get the macro to work.

    I have a csv file in open in excel with a column that contains the partial path and filename of wav files (e.g. "dira\new\boom.wav"). The root of the path will always be "C:\sounds\". I want to add a macro to my PERSONAL.XLSB workbook so that I can add a button to a custom ribbon for the macro that will play the wav file in the currently selected cell. That way I can keep the file in csv format, and can use the same macro on other csv files which will also have path\filenames in the same column, and have the same root path.

    Can someone please help me and let me know how to do this? So far all I've been able to do is get a macro to play a beep instead of the wav file in the selected cell.

    Thank you!
    Last edited by needtoregistersux; 03-31-2016 at 07:47 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    03-30-2016
    Location
    nowhere
    MS-Off Ver
    2014
    Posts
    7

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    Quote Originally Posted by AlphaFrog View Post
    Please Login or Register  to view this content.
    Thanks! This works... but not always. For some reason, sometimes the sound will play. Other times, it will just play a short beep. This is even happening with two sounds in the same folder, with the same sample rate & bit depth, both stereo wav files of about the same length. No idea why one will play and the other wont. Any ideas?

  4. #4
    Registered User
    Join Date
    03-30-2016
    Location
    nowhere
    MS-Off Ver
    2014
    Posts
    7

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    Also, I had to modify the declare with PtrSafe to get it to work. I am using Excel 2010 on a Windows 10 PC. I'd really love to know why the beep plays sometimes instead of the wav file, because the files definitely do exist, and are the same format as a number of other files that do play in the same folder, with the exact same attributes. Really frustrating that some just don't play while others do. No clue why.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    Quote Originally Posted by needtoregistersux View Post
    Thanks! This works... but not always. For some reason, sometimes the sound will play. Other times, it will just play a short beep. This is even happening with two sounds in the same folder, with the same sample rate & bit depth, both stereo wav files of about the same length. No idea why one will play and the other wont. Any ideas?

    I have no idea. Sorry.

    Try this. Just a shot in the dark.
    sndPlaySound strFile, 0

  6. #6
    Registered User
    Join Date
    03-30-2016
    Location
    nowhere
    MS-Off Ver
    2014
    Posts
    7

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    Yeah changing it to 0 didn't work. Darn. So close. I sure hope someone knows why this is happening.

  7. #7
    Registered User
    Join Date
    03-30-2016
    Location
    nowhere
    MS-Off Ver
    2014
    Posts
    7

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    Adding the following at least stops the beep from playing.

    Please Login or Register  to view this content.
    Thus making the flag a 3.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    03-30-2016
    Location
    nowhere
    MS-Off Ver
    2014
    Posts
    7

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    Eureka! I discovered the cause of the problem!

    I've had issues with this in the past, so thought to take a look and see. Opening a few of the files in notepad, I was able to see that the ones that played were "RIFFˇ«; WAVEfmt" in the header, while those that don't play are "RIFF¢0 WAVEJUNK\", which are wav files exported from Pro Tools.

    After touching the files in Sound Forge and saving them, they play just fine using the macro!

    Yet another reason to hate Pro Tools. LOL!

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    Excellent! Thanks for the feedback.

  10. #10
    Registered User
    Join Date
    03-30-2016
    Location
    nowhere
    MS-Off Ver
    2014
    Posts
    7

    Re: Need to play a wav file based on path and filename in a selected cell using a macro

    No problem. Glad I could give something back. Thank you for helping me to get this working! It's going to be a major time saver in my workflow.

+ 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. Find filename and path of a linked file in another cell
    By Tsangman007 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-02-2015, 01:35 AM
  2. Macro to open a file and folder that has date in the path based on a cell value
    By mm671750 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-07-2015, 06:31 PM
  3. Find File with partial filename and get path of folder
    By axisambrosia in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-16-2012, 06:51 AM
  4. Extracting the folder name and filename from a file path?
    By Skywalker in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2012, 08:17 PM
  5. [SOLVED] Excel Macro: How to open a file with selected path?
    By polimer in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2012, 02:29 PM
  6. Run Macro on cell change to update path and filename for query
    By Gary Brown in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2011, 08:05 AM
  7. Play wav sound when cell is selected
    By Synthia in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-25-2009, 12:40 PM

Tags for this Thread

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