+ Reply to Thread
Results 1 to 13 of 13

Playing embedded WAV files from excel.

  1. #1
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Playing embedded WAV files from excel.

    While providing some help from another user on here I came across the following code which will play a .wav file from VBA without launching any third party apps (like winamp or windoze media player):

    Please Login or Register  to view this content.
    And it works well.

    However, I'd like to embed the wav files in question into my workbook and play them from there without having to make a user download them as separate files. So....I looked around and found the following:

    Insert > Object... > Create from File > C:\Folder\filename.WAV

    and then play it by either:

    Please Login or Register  to view this content.
    or


    Please Login or Register  to view this content.
    The problem with both the methods of playing the embedded file is that it will try to launch the systems default .wav file player. This means the user will get a message saying "Do you want to open this" and if the default wav player is winamp and (like mine) is set to repeat the playlist, the wav isn't just played once.


    Is there any way to combine to two methods above? ie, have the .wav file embedded in a workbook but play it using the "sndPlaySound" method which doesn't launch an external .wav player?

    I've tried replacing the file location with activesheet.shapes("object 1") but get a "doesn't support this method" error.

  2. #2
    Registered User
    Join Date
    03-28-2013
    Location
    Kent, Engmland
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Playing embedded WAV files from excel.

    Its been a while since you posted this and I was looking for the same thing. Any chance you sorted this out?

  3. #3
    Registered User
    Join Date
    06-13-2019
    Location
    Edinburgh
    MS-Off Ver
    2016
    Posts
    7

    Re: Playing embedded WAV files from excel.

    Hi, I'm aware that this question has been posted a long-time ago. Now the systems are 64 bit and when I try to run this code I get: "Compile error: The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute". I don't know how? I'd like to play wav mp3 and possibly other audio formats inside Excel. Can anybody help? I'm pretty new in the field of VBA in Excel.

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Playing embedded WAV files from excel.

    Good morning LuBuExc

    Untested, as I don't have Office 64 bit,but try this :
    Please Login or Register  to view this content.
    If this doesn't work, then please open a new thread on the subject.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  5. #5
    Registered User
    Join Date
    06-13-2019
    Location
    Edinburgh
    MS-Off Ver
    2016
    Posts
    7

    Re: Playing embedded WAV files from excel.

    Thanks DominicB.
    The declaration part seems now to be fine, but it stops in the sub playit.
    "My" code is now:
    Please Login or Register  to view this content.
    It stops at sndPlaySound and says Compile error: Sub or Function not defined.
    Probably I'm doing something very stupid. If we can't solve I'll try a new thread as you suggested. Thanks LuBu
    Last edited by dominicb; 08-08-2019 at 07:08 AM.

  6. #6
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Playing embedded WAV files from excel.

    Hi LuBuExc

    Try the amendment below :
    Please Login or Register  to view this content.


    Administrative Note:

    Welcome to the forum.

    Next time you post, please remember you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I have edited your post to include code tags.

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Playing embedded WAV files from excel.

    The 64bit equivalent of the original would just be:

    Please Login or Register  to view this content.
    Change highlighted. PlaySound is actually a different function and takes three arguments.
    Rory

  8. #8
    Registered User
    Join Date
    06-13-2019
    Location
    Edinburgh
    MS-Off Ver
    2016
    Posts
    7

    Re: Playing embedded WAV files from excel.

    Thanks DominicB. Unfortunately it still doesn't run. It stops at PlaySound in the Sub and says: Compile error: Argument not optional.
    Any further ideas for me? Best regards LuBu

  9. #9
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Playing embedded WAV files from excel.

    LuBuExc

    Have you tried rorya's suggestion?

    HTH

    DominicB

  10. #10
    Registered User
    Join Date
    06-13-2019
    Location
    Edinburgh
    MS-Off Ver
    2016
    Posts
    7

    Re: Playing embedded WAV files from excel.

    Thanks rorya. This now works. I add the working code now.


    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-13-2019
    Location
    Edinburgh
    MS-Off Ver
    2016
    Posts
    7

    Re: Playing embedded WAV files from excel.

    Thanks again to rorya and dominicb. The posted code works for wav files. I have tested and run with various. Is there also a solution for playing mp3 or even m4a in a similar manner?

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Playing embedded WAV files from excel.

    Quote Originally Posted by LuBuExc View Post
    Thanks again to rorya and dominicb. The posted code works for wav files. I have tested and run with various. Is there also a solution for playing mp3 or even m4a in a similar manner?
    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  13. #13
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,907

    Re: Playing embedded WAV files from excel.

    IIRC you can use mciSendString to launch whatever the default player is, but I don't know if there is an API that will play either of those formats directly.

+ 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