How can I embed a simple sound file into an Excel application and play it using VBA?

Hi all,

How can I embed a simple sound file into an Excel application and play it using VBA?

thanks

Avi
progtwAsked:
Who is Participating?
 
DarthModConnect With a Mentor Commented:
PAQed with points refunded (125)

DarthMod
Community Support Moderator
0
 
progtwAuthor Commented:
Hi all again,

Sorry. I meant to ask:

How can I embed a simple sound file into an Excel *sheet* and then play it using VBA (e.g., when somebody opens the sheet)?

thanks

Avi
0
 
bruintjeCommented:
Hi progtw,
----------

not sure but i don't think you can embed a sound file into Excel, maybe a flash animation but not something like a wav

you can play it through VBA
http://www.exceltip.com/st/Playing_WAV-files_using_VBA_in_Microsoft_Excel/460.html

and call the sub through the Workbook_Open event
http://www.ozgrid.com/VBA/auto-run-macros.htm

----------
bruintje
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
progtwAuthor Commented:
Thanks. I will get back to you , one I have tried it out.

avi
0
 
progtwAuthor Commented:
>> not sure but i don't think you can embed a sound file into Excel
Yes you can. I did it.

avi
0
 
bruintjeCommented:
great how did you do it?
0
 
progtwAuthor Commented:
Simple. I just did:

1. Click the Insert menu.

2. Select the Object command.

3. Click the Browse tab.

4. Look for your file, e.g. a WAV file.

5. Double click.
   Object is inserted on current cell.

6. Right click on object. And select the Run or Activate command.

Do I get points?

avi


0
 
bruintjeCommented:
you can get a refund by asking a 0 point question with a link to this one here
http://www.experts-exchange.com/Community_Support/

and you have the good feeling of helping future requests for this same situation :-)
0
 
stochasticCommented:
avi,

If I understand the interaction correctly, you know how to insert a sound object into Excel.
But that still doesn't answer your question about how to play it when the workbook is opened.
Is that correct?

SoundNote objects were removed from the Excel object model after XL97. However you can still
make a API call to play an external sound file (not one that's embedded).

See http://www.j-walk.com/ss/excel/tips/tip59.htm (thanks to John Walkenback)

To auto-play it on opening worksheet is a simple additional step:
insert that code into
Private Sub Workbook_Open()
   
in your workbook code. (If you need help on how to do that, please ask).

cheers - stochastic
0
 
progtwAuthor Commented:
>> SoundNote objects were removed from the Excel object model after XL97
Dumb question - Why were SoundNote objects were removed from the Excel object model after XL97

(We are supposed to be geeting more sophisticated. So why are features being taken out...?)

>> However you can still make a API call to play an external sound file (not one that's embedded).
Not good enough. I wanted to send a file through email and make it sing when the recipient opens it...

avi

0
 
stochasticCommented:
>> Dumb question - Why were SoundNote objects were removed from the Excel object model after XL97
I really don't know. Perhaps bruintje will tell us.

But there _is_ a way. By doing Insert->Object->From File, you can insert a sound object (say from a wav file).

And you can actually play that object on file open by putting the following code in workbook_open event.

Private Sub Workbook_Open()
    ActiveSheet.Shapes("Object 1").Select
    Selection.Verb Verb:=xlPrimary
End Sub

Mind you - since the file will contain a macro, your user _will_ get a macro warning unless security setting is Low.
And that (macro warning) might spoil the fun if you wanted to surprise the user!

Still, for whatever it is worth ....

If you want a sample file uploaded please let me know.

- sto

0
 
stochasticCommented:
I think the asker got reasonable answers that fully satisfy
the need, so I don't see a case for a refund. At the very least, not without
the asker explicitly articulating that the answer wasn't good enough, and asking
for a delete / refund.

- stochastic

0
All Courses

From novice to tech pro — start learning today.