Can you play sound via VBA?

You can also add the Media Player control. Then simply have:

MediaPlayer1.Open ("C:Tada.wav")

How can I use this control to play an embedded object in my worksheet? (i.e. I have a wav file that is a SHAPE on a worksheet.)

_________________
Pass on what you have learned. Support this great website by clicking on the sponsor's ads!.
This message was edited by phantom1975 on 2002-08-23 00:52
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Ivan
I have put the code into the Declarations part of my code, but the compiler is saying "constants, fixed length strings, arrays, user-defined types and declare statements are not allowed as Public members of object modules" and the "Public" line is highlighted.

Option Explicit

Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_MEMORY = &H4
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10

this is all I have in the (General) (Declarations) section. After this , my code continues with the sub Wavstop() sub-routine. is there another (Declarations) area I should have put it in ? Any ideas how to get past this error.
 
Upvote 0
Hi Bill, put the code in a STD Module and
not a Sheet code module ie.
While in VBA Editor Press Ctrl + R (Project explorer ...right click on the Xlobject select Insert > Module
 
Upvote 0
Ivan, that works fine now. thanks for your help.

If you have the time, could you do me one of your great explanations about the difference between that Declaration area and the code Declaration area. I am trying to learn VBA so if you know of any really good Tutorial sites that goes from novice right through to this level ( and beyond !) I would appreciate the link.
Thanks again
Bill
 
Upvote 0
On 2002-08-23 00:27, phantom1975 wrote:
You can also add the Media Player control. Then simply have:

MediaPlayer1.Open ("C:Tada.wav")

How can I use this control to play an embedded object in my worksheet? (i.e. I have a wav file that is a SHAPE on a worksheet.)

_________________
Pass on what you have learned. Support this great website by clicking on the sponsor's ads!.
This message was edited by phantom1975 on 2002-08-23 00:52

Mr Walker :)
There is no need to use the media player to play this. Just use the shapes OLE default action ie. recording a macro then double clicking on the shape to play it....Just remember the Shape is actually an OLE reference to the Sound file > sound file has default application to Action this. Whilst it is embeded it still has a File reference to your Sound file ie. changing the Original path will not play it! (File name is Linked)
 
Upvote 0
On 2002-08-23 03:56, Billm wrote:
Ivan, that works fine now. thanks for your help.

If you have the time, could you do me one of your great explanations about the difference between that Declaration area and the code Declaration area. I am trying to learn VBA so if you know of any really good Tutorial sites that goes from novice right through to this level ( and beyond !) I would appreciate the link.
Thanks again
Bill

Hi Bill
Never tried these BUT

http://www.add-ins.com/pages
http://www.vbatutor.com/vbatutor.htm

Plus any of the MVP sites
 
Upvote 0
How do I embed a sound file then? For instance, if I reference a sound file that is on MY computer but NOT the user's computer, then an error will occur because VB cannot find the sound file. Instead, I want to have the sound file "attached" to the spreadsheet so that the sound file travels with the spreadsheet file.
 
Upvote 0
I'd imagine using "Insert|Object|Create From File" would embed the sound file on your worksheet. I've used this trick many times. (ok, once)
 
Upvote 0
That's what I have done too. In order to reference the sound file, you have to refer to it as a SHAPE. According to Ivan's post, the sound file is merely a reference to the file's location on the hard drive instead of embedding the file itself. Is it possible to use this "embedded" file using the MediaPlayer control?
 
Upvote 0
On 2002-08-23 14:30, phantom1975 wrote:
That's what I have done too. In order to reference the sound file, you have to refer to it as a SHAPE. According to Ivan's post, the sound file is merely a reference to the file's location on the hard drive instead of embedding the file itself. Is it possible to use this "embedded" file using the MediaPlayer control?

What you have to do is CREATE it as a PACKAGE
and NOT from a file AND then IMPORT the sound file. You don't need to use the media player to reference the Embedded file.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,428
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top